summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-11-04 21:45:44 +0100
committerGitHub <noreply@github.com>2020-11-04 21:45:44 +0100
commitc3969d94930e0102368c356c8ba2eb2526dd3fb3 (patch)
tree592f3852e3c7a9edf231ad8a823aae0f42aa01e0 /apps
parenteb9faa7bdbb5db60a4189299196b894e12dd795d (diff)
parent8bd39fccf411195839f2dadee085fad18ec52c23 (diff)
downloadnextcloud-server-c3969d94930e0102368c356c8ba2eb2526dd3fb3.tar.gz
nextcloud-server-c3969d94930e0102368c356c8ba2eb2526dd3fb3.zip
Merge pull request #23792 from nextcloud/techdebt/noid/group-unread-comment-count-query
Add a function to get the unread count for multiple objects in one go
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php45
1 files changed, 27 insertions, 18 deletions
diff --git a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php
index d5eb7062dd1..add69367fc8 100644
--- a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php
@@ -47,8 +47,6 @@ class CommentPropertiesPlugin extends ServerPlugin {
private $cachedUnreadCount = [];
- private $cachedFolders = [];
-
public function __construct(ICommentsManager $commentsManager, IUserSession $userSession) {
$this->commentsManager = $commentsManager;
$this->userSession = $userSession;
@@ -70,6 +68,31 @@ class CommentPropertiesPlugin extends ServerPlugin {
$this->server->on('propFind', [$this, 'handleGetProperties']);
}
+ private function cacheDirectory(Directory $directory) {
+ $children = $directory->getChildren();
+
+ $ids = [];
+ foreach ($children as $child) {
+ if (!($child instanceof File || $child instanceof Directory)) {
+ continue;
+ }
+
+ $id = $child->getId();
+ if ($id === null) {
+ continue;
+ }
+
+ $ids[] = (string)$id;
+ }
+
+ $ids[] = (string) $directory->getId();
+ $unread = $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', $ids, $this->userSession->getUser());
+
+ foreach ($unread as $id => $count) {
+ $this->cachedUnreadCount[(int)$id] = $count;
+ }
+ }
+
/**
* Adds tags and favorites properties to the response,
* if requested.
@@ -91,11 +114,7 @@ class CommentPropertiesPlugin extends ServerPlugin {
&& $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;
- }
+ $this->cacheDirectory($node);
}
$propFind->handle(self::PROPERTY_NAME_COUNT, function () use ($node) {
@@ -109,18 +128,8 @@ class CommentPropertiesPlugin extends ServerPlugin {
$propFind->handle(self::PROPERTY_NAME_UNREAD, function () use ($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 comments for this file
- if (array_search($parentPath, $this->cachedFolders) === false) {
- return 0;
- } else {
- return $this->getUnreadCount($node);
- }
}
+ return $this->getUnreadCount($node);
});
}