diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-04-10 13:21:39 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-10 13:21:39 -0500 |
commit | a045f3c4d7ef606ea302712952ec474d5ea5637a (patch) | |
tree | 4edf7b74e8220a4ed06fc1f3e9b2b7064e21cd6a /apps | |
parent | a750436ebc3a71f4fe34596cc0bdb1f9b61ba912 (diff) | |
parent | 11c1e5dd8641e38c44e49d0f527444be7f92da1b (diff) | |
download | nextcloud-server-a045f3c4d7ef606ea302712952ec474d5ea5637a.tar.gz nextcloud-server-a045f3c4d7ef606ea302712952ec474d5ea5637a.zip |
Merge pull request #4146 from nextcloud/unread-comments-folder
Allow getting the unread comment count for an entire folder at once
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php index e48105f6d7a..66d6b335f40 100644 --- a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php @@ -42,6 +42,10 @@ class CommentPropertiesPlugin extends ServerPlugin { /** @var IUserSession */ private $userSession; + private $cachedUnreadCount = []; + + private $cachedFolders = []; + public function __construct(ICommentsManager $commentsManager, IUserSession $userSession) { $this->commentsManager = $commentsManager; $this->userSession = $userSession; @@ -79,6 +83,18 @@ class CommentPropertiesPlugin extends ServerPlugin { return; } + // need prefetch ? + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory + && $propFind->getDepth() !== 0 + && !is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD)) + ) { + $unreadCounts = $this->commentsManager->getNumberOfUnreadCommentsForFolder($node->getId(), $this->userSession->getUser()); + $this->cachedFolders[] = $node->getPath(); + foreach ($unreadCounts as $id => $count) { + $this->cachedUnreadCount[$id] = $count; + } + } + $propFind->handle(self::PROPERTY_NAME_COUNT, function() use ($node) { return $this->commentsManager->getNumberOfCommentsForObject('files', strval($node->getId())); }); @@ -88,7 +104,20 @@ class CommentPropertiesPlugin extends ServerPlugin { }); $propFind->handle(self::PROPERTY_NAME_UNREAD, function() use ($node) { - return $this->getUnreadCount($node); + if (isset($this->cachedUnreadCount[$node->getId()])) { + return $this->cachedUnreadCount[$node->getId()]; + } else { + list($parentPath,) = \Sabre\Uri\split($node->getPath()); + if ($parentPath === '') { + $parentPath = '/'; + } + // if we already cached the folder this file is in we know there are no shares for this file + if (array_search($parentPath, $this->cachedFolders) === false) { + return $this->getUnreadCount($node); + } else { + return 0; + } + } }); } |