From 7988f7d68c04cd73cb170e3a4db58427297ea3ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Mon, 22 Mar 2010 16:47:40 +0100 Subject: [PATCH] No need for batch loading of Photo data MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- classes/profile.php | 35 +++++++++++++++-------------------- include/profilefields.inc.php | 30 ------------------------------ modules/profile.php | 2 +- 3 files changed, 16 insertions(+), 51 deletions(-) diff --git a/classes/profile.php b/classes/profile.php index a466fe2..951e6f2 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -89,9 +89,8 @@ class Profile const FETCH_MEDALS = 0x000010; const FETCH_NETWORKING = 0x000020; const FETCH_PHONES = 0x000040; - const FETCH_PHOTO = 0x000080; - const FETCH_MINIFICHES = 0x0000CD; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_PHONES | FETCH_PHOTO + const FETCH_MINIFICHES = 0x00004D; // FETCH_ADDRESSES | FETCH_EDU | FETCH_JOBS | FETCH_PHONES const FETCH_ALL = 0x0000FF; // OR of FETCH_* @@ -340,20 +339,23 @@ class Profile /* Photo */ - private $photo = null; - public function setPhoto(ProfilePhoto $photo) + private $_photo = null; + public function getPhoto($fallback = true, $data = false) { - $this->photo = $photo; - } + if ($data && $this->has_photo && $this->isVisible($this->photo_pub) && + ($this->_photo == null || $this->_photo->mimeType() == null)) { + $res = XDB::fetchOneAssoc('SELECT attach, attachmime, x, y + FROM profile_photos + WHERE pid = {?}', $this->pid); + $this->_photo = PlImage::fromData($res['attach'], $res['attachmime'], $res['x'], $res['y']); + } - public function getPhoto($fallback = true) - { - if ($this->photo == null) { - $this->setPhoto($this->getProfileField('ProfilePhoto')); + if (!$data && $this->_photo == null) { + $this->_photo = PlImage::fromData(null, null, $this->photo_width, $this->photo_height); } - if ($this->photo != null) { - return $this->photo->pic; + if ($this->has_photo && $this->isVisible($this->photo_pub)) { + return $this->_photo; } else if ($fallback) { return PlImage::fromFile(dirname(__FILE__).'/../htdocs/images/none.png', 'image/png'); @@ -598,6 +600,7 @@ class Profile pd.promo AS promo, pd.short_name, pd.directory_name AS full_name, pd.directory_name, pp.display_tel AS mobile, pp.pub AS mobile_pub, ph.attach IS NOT NULL AS has_photo, ph.pub AS photo_pub, + ph.x AS photo_width, ph.y AS photo_height, p.last_change < DATE_SUB(NOW(), INTERVAL 365 DAY) AS is_old, pm.expertise AS mentor_expertise, ap.uid AS owner_id @@ -875,11 +878,6 @@ class ProfileIterator implements PlIterator $subits[Profile::FETCH_PHONES] = new ProfileFieldIterator('ProfilePhones', $pids, $visibility); } - if ($fields & Profile::FETCH_PHOTO) { - $callbacks[Profile::FETCH_PHOTO] = $cb; - $subits[Profile::FETCH_PHOTO] = new ProfileFieldIterator('ProfilePhoto', $pids, $visibility); - } - $this->iterator = PlIteratorUtils::parallelIterator($subits, $callbacks, 0); } @@ -913,9 +911,6 @@ class ProfileIterator implements PlIterator if ($this->hasData(Profile::FETCH_NETWORKING, $vals)) { $pf->setNetworking($vals[Profile::FETCH_NETWORKING]); } - if ($this->hasData(Profile::FETCH_PHOTO, $vals)) { - $pf->setPhoto($vals[Profile::FETCH_PHOTO]); - } return $pf; } diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index adcb128..5641072 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -456,36 +456,6 @@ class ProfileNetworking extends ProfileField } } // }}} -// {{{ class ProfilePhoto [ Field ] -class ProfilePhoto extends ProfileField -{ - public $pic; - - public function __construct(array $data) - { - if ($data == null || count($data) == 0) { - $this->pic = null; - } else { - $this->pid = $data['pid']; - $this->pic = PlImage::fromDATA($data['attach'], - $data['attachmime'], - $data['x'], - $data['y']); - } - } - - public static function fetchData(array $pids, $visibility) - { - $data = XDB::iterator('SELECT * - FROM profile_photos - WHERE pid IN {?} AND attachmime IN (\'jpeg\', \'png\') AND pub IN {?} - ORDER BY ' . XDB::formatCustomOrder('pid', $pids), - $pids, $visibility); - - return $data; - } -} -// }}} // {{{ class ProfileCorps [ Field ] class ProfileCorps extends ProfileField { diff --git a/modules/profile.php b/modules/profile.php index 75c1d71..40bff74 100644 --- a/modules/profile.php +++ b/modules/profile.php @@ -94,7 +94,7 @@ class ProfileModule extends PLModule $myphoto = PhotoReq::get_request($profile->owner()->id()); $photo = PlImage::fromData($myphoto->data, $myphoto->mimetype); } else { - $photo = $profile->getPhoto(true); + $photo = $profile->getPhoto(true, true); } // Display the photo, or a default one when not available. -- 2.1.4