Load more items in recent activity list than necessary to avoid empty list if some...
authorMarcel Werk <burntime@woltlab.com>
Fri, 15 Jul 2016 11:03:03 +0000 (13:03 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 15 Jul 2016 11:03:03 +0000 (13:03 +0200)
wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEventList.class.php
wcfsetup/install/files/lib/page/RecentActivityListPage.class.php
wcfsetup/install/files/lib/system/box/RecentActivityListBoxController.class.php
wcfsetup/install/files/lib/system/menu/user/profile/content/RecentActivityUserProfileMenuContent.class.php

index 9274f6e14d79e9372dc28211296195048c185efe..940302e9bef9a2f009c358828b5d9c234a696978 100644 (file)
@@ -123,4 +123,14 @@ class ViewableUserActivityEventList extends UserActivityEventList {
                
                return $orphanedEventIDs;
        }
+       
+       /**
+        * Truncates the items in object list to given number of items.
+        * 
+        * @param       integer         $limit
+        */
+       public function truncate($limit) {
+               $this->objects = array_slice($this->objects, 0, $limit, true);
+               $this->indexToObject = array_keys($this->objects);
+       }
 }
index f5585002ce8ff6bf836979d7578b002335608050..e5389161e39e3cddcdb3fdd7929d82eb2969ac85 100644 (file)
@@ -37,6 +37,10 @@ class RecentActivityListPage extends AbstractPage {
                parent::readData();
                
                $this->eventList = new ViewableUserActivityEventList();
+               
+               // load more items than necessary to avoid empty list if some items are invisible for current user
+               $this->eventList->sqlLimit = 60;
+               
                $this->eventList->readObjects();
                
                // add breadcrumbs
@@ -54,6 +58,9 @@ class RecentActivityListPage extends AbstractPage {
                // removes orphaned and non-accessible events
                UserActivityEventHandler::validateEvents($this->eventList);
                
+               // remove unused items
+               $this->eventList->truncate(20);
+                               
                WCF::getTPL()->assign([
                        'eventList' => $this->eventList,
                        'lastEventTime' => $lastEventTime,
index f3f3a62a2f38aa3ff93540290448e88211c81988..5ec8ccc5255b9626e229ccf5d55a134cb21d8f63 100644 (file)
@@ -13,6 +13,8 @@ use wcf\system\WCF;
  * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
  * @package    WoltLabSuite\Core\System\Box
  * @since      3.0
+ *        
+ * @property   ViewableUserActivityEventList   $objectList
  */
 class RecentActivityListBoxController extends AbstractDatabaseObjectListBoxController {
        /**
@@ -116,10 +118,16 @@ class RecentActivityListBoxController extends AbstractDatabaseObjectListBoxContr
                        $this->objectList->getConditionBuilder()->add('user_activity_event.userID IN (?)', [WCF::getUserProfileHandler()->getFollowingUsers()]);
                }
                
+               // load more items than necessary to avoid empty list if some items are invisible for current user
+               $this->objectList->sqlLimit = $this->box->limit * 3;
+               
                parent::readObjects();
                
-               // removes orphaned and non-accessable events
+               // removes orphaned and non-accessible events
                /** @noinspection PhpParamsInspection */
                UserActivityEventHandler::validateEvents($this->objectList);
+               
+               // remove unused items
+               $this->objectList->truncate($this->box->limit);
        }
 }
index 99a275e28df43f6cfd610d42f45456bfa633e8be..1e34b9f62ccaf2445d162c7c58dae15f5b958dc7 100644 (file)
@@ -19,6 +19,10 @@ class RecentActivityUserProfileMenuContent extends SingletonFactory implements I
         */
        public function getContent($userID) {
                $eventList = new ViewableUserActivityEventList();
+               
+               // load more items than necessary to avoid empty list if some items are invisible for current user
+               $eventList->sqlLimit = 60;
+               
                $eventList->getConditionBuilder()->add("user_activity_event.userID = ?", [$userID]);
                $eventList->readObjects();
                
@@ -27,6 +31,9 @@ class RecentActivityUserProfileMenuContent extends SingletonFactory implements I
                        UserActivityEventHandler::validateEvents($eventList);
                }
                
+               // remove unused items
+               $eventList->truncate(20);
+               
                WCF::getTPL()->assign([
                        'eventList' => $eventList,
                        'lastEventTime' => $lastEventTime,