From: Marcel Werk Date: Fri, 15 Jul 2016 11:03:03 +0000 (+0200) Subject: Load more items in recent activity list than necessary to avoid empty list if some... X-Git-Tag: 3.0.0_Beta_1~1126 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b91831d66adfddd5701a6b9f1d0fe48e1a21fb17;p=GitHub%2FWoltLab%2FWCF.git Load more items in recent activity list than necessary to avoid empty list if some items are invisible for current user --- diff --git a/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEventList.class.php b/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEventList.class.php index 9274f6e14d..940302e9be 100644 --- a/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEventList.class.php +++ b/wcfsetup/install/files/lib/data/user/activity/event/ViewableUserActivityEventList.class.php @@ -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); + } } diff --git a/wcfsetup/install/files/lib/page/RecentActivityListPage.class.php b/wcfsetup/install/files/lib/page/RecentActivityListPage.class.php index f5585002ce..e5389161e3 100644 --- a/wcfsetup/install/files/lib/page/RecentActivityListPage.class.php +++ b/wcfsetup/install/files/lib/page/RecentActivityListPage.class.php @@ -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, diff --git a/wcfsetup/install/files/lib/system/box/RecentActivityListBoxController.class.php b/wcfsetup/install/files/lib/system/box/RecentActivityListBoxController.class.php index f3f3a62a2f..5ec8ccc525 100644 --- a/wcfsetup/install/files/lib/system/box/RecentActivityListBoxController.class.php +++ b/wcfsetup/install/files/lib/system/box/RecentActivityListBoxController.class.php @@ -13,6 +13,8 @@ use wcf\system\WCF; * @license GNU Lesser General Public License * @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); } } diff --git a/wcfsetup/install/files/lib/system/menu/user/profile/content/RecentActivityUserProfileMenuContent.class.php b/wcfsetup/install/files/lib/system/menu/user/profile/content/RecentActivityUserProfileMenuContent.class.php index 99a275e28d..1e34b9f62c 100644 --- a/wcfsetup/install/files/lib/system/menu/user/profile/content/RecentActivityUserProfileMenuContent.class.php +++ b/wcfsetup/install/files/lib/system/menu/user/profile/content/RecentActivityUserProfileMenuContent.class.php @@ -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,