]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
use an array of profiles rather than a looping cursor for profile lists
authorEvan Prodromou <evan@status.net>
Sat, 27 Aug 2011 16:53:15 +0000 (12:53 -0400)
committerEvan Prodromou <evan@status.net>
Sat, 27 Aug 2011 16:53:15 +0000 (12:53 -0400)
classes/Profile.php
lib/profilelist.php
lib/profileminilist.php
plugins/Directory/lib/sortablesubscriptionlist.php

index 228a0ae2028fc0a61b1d0a55f98420a496ad1b20..06ea31c4352d12e098df7b9d7920f60903cba96d 100644 (file)
@@ -98,7 +98,7 @@ class Profile extends Managed_DataObject
         return $this->_user;
     }
 
-       protected $_avatars = array();
+       protected $_avatars;
        
     function getAvatar($width, $height=null)
     {
@@ -106,6 +106,10 @@ class Profile extends Managed_DataObject
             $height = $width;
         }
 
+        if (!isset($this->_avatars)) {
+            $this->_avatars = array();
+        }
+
                if (array_key_exists($width, $this->_avatars)) {
                        return $this->_avatars[$width];
                }
index 90e1c743a5e063da7cfea5fa3d633f0852967fa2..9039d1b6d87cdced07fe4eaaed98a7b3c6e3113e 100644 (file)
@@ -85,14 +85,14 @@ class ProfileList extends Widget
 
     function showProfiles()
     {
-        $cnt = 0;
+        $profiles = $this->profile->fetchAll();
 
-        while ($this->profile->fetch()) {
-            $cnt++;
-            if($cnt > PROFILES_PER_PAGE) {
-                break;
-            }
-            $pli = $this->newListItem($this->profile);
+        $cnt = count($profiles);
+
+        $max = min($cnt, $this->maxProfiles());
+
+        for ($i = 0; $i < $max; $i++) {
+            $pli = $this->newListItem($profiles[$i]);
             $pli->show();
         }
 
@@ -101,7 +101,17 @@ class ProfileList extends Widget
 
     function newListItem($profile)
     {
-        return new ProfileListItem($this->profile, $this->action);
+        return new ProfileListItem($profile, $this->action);
+    }
+
+    function maxProfiles()
+    {
+        return PROFILES_PER_PAGE;
+    }
+
+    function avatarSize()
+    {
+        return AVATAR_STREAM_SIZE;
     }
 }
 
@@ -186,7 +196,7 @@ class ProfileListItem extends Widget
         $avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
         $aAttrs = $this->linkAttributes();
         $this->out->elementStart('a', $aAttrs);
-        $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
+        $this->out->element('img', array('src' => (!empty($avatar)) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
                                          'class' => 'photo avatar',
                                          'width' => AVATAR_STREAM_SIZE,
                                          'height' => AVATAR_STREAM_SIZE,
index 36bfad770cf02a01cf081131abc0851a79872908..2c3fc4642d9f92fb80994d2d4026e50481db9c79 100644 (file)
@@ -58,22 +58,15 @@ class ProfileMiniList extends ProfileList
         return new ProfileMiniListItem($profile, $this->action);
     }
 
-    function showProfiles()
+    function maxProfiles()
     {
-        $cnt = 0;
-
-        while ($this->profile->fetch()) {
-            $cnt++;
-            if ($cnt > PROFILES_PER_MINILIST) {
-                break;
-            }
-            $pli = $this->newListItem($this->profile);
-            $pli->show();
-        }
-
-        return $cnt;
+        return PROFILES_PER_MINILIST;
     }
 
+    function avatarSize()
+    {
+        return AVATAR_MINI_SIZE;
+    }
 }
 
 class ProfileMiniListItem extends ProfileListItem
index 234923c00323f3c904b44f44ef8892e265b07c7c..b61f760ef4cdc1aab0ed064d5cf754803f417c38 100644 (file)
@@ -130,17 +130,15 @@ class SortableSubscriptionList extends SubscriptionList
 
     function showProfiles()
     {
-        $cnt = 0;
+        $profiles = $this->profile->fetchAll();
 
-        while ($this->profile->fetch()) {
-            $cnt++;
-            if($cnt > PROFILES_PER_PAGE) {
-                break;
-            }
+        $cnt = count($profiles);
 
-            $odd = ($cnt % 2 == 0); // for zebra striping
+        $max = min($cnt, $this->maxProfiles());
 
-            $pli = $this->newListItem($this->profile, $odd);
+        for ($i = 0; $i < $max; $i++) {
+            $odd = ($i % 2 == 0); // for zebra striping
+            $pli = $this->newListItem($profiles[$i], $odd);
             $pli->show();
         }