aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php')
-rw-r--r--apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php40
1 files changed, 25 insertions, 15 deletions
diff --git a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php
index 71514016bda..ef9bd1ae472 100644
--- a/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/CommentPropertiesPlugin.php
@@ -10,6 +10,7 @@ namespace OCA\DAV\Connector\Sabre;
use OCP\Comments\ICommentsManager;
use OCP\IUserSession;
+use Sabre\DAV\ICollection;
use Sabre\DAV\PropFind;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
@@ -20,13 +21,13 @@ class CommentPropertiesPlugin extends ServerPlugin {
public const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}comments-unread';
protected ?Server $server = null;
- private ICommentsManager $commentsManager;
- private IUserSession $userSession;
private array $cachedUnreadCount = [];
+ private array $cachedDirectories = [];
- public function __construct(ICommentsManager $commentsManager, IUserSession $userSession) {
- $this->commentsManager = $commentsManager;
- $this->userSession = $userSession;
+ public function __construct(
+ private ICommentsManager $commentsManager,
+ private IUserSession $userSession,
+ ) {
}
/**
@@ -42,6 +43,8 @@ class CommentPropertiesPlugin extends ServerPlugin {
*/
public function initialize(\Sabre\DAV\Server $server) {
$this->server = $server;
+
+ $this->server->on('preloadCollection', $this->preloadCollection(...));
$this->server->on('propFind', [$this, 'handleGetProperties']);
}
@@ -62,7 +65,7 @@ class CommentPropertiesPlugin extends ServerPlugin {
$ids[] = (string)$id;
}
- $ids[] = (string) $directory->getId();
+ $ids[] = (string)$directory->getId();
$unread = $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', $ids, $this->userSession->getUser());
foreach ($unread as $id => $count) {
@@ -70,6 +73,21 @@ class CommentPropertiesPlugin extends ServerPlugin {
}
}
+ private function preloadCollection(PropFind $propFind, ICollection $collection):
+ void {
+ if (!($collection instanceof Directory)) {
+ return;
+ }
+
+ $collectionPath = $collection->getPath();
+ if (!isset($this->cachedDirectories[$collectionPath]) && $propFind->getStatus(
+ self::PROPERTY_NAME_UNREAD
+ ) !== null) {
+ $this->cacheDirectory($collection);
+ $this->cachedDirectories[$collectionPath] = true;
+ }
+ }
+
/**
* Adds tags and favorites properties to the response,
* if requested.
@@ -80,20 +98,12 @@ class CommentPropertiesPlugin extends ServerPlugin {
*/
public function handleGetProperties(
PropFind $propFind,
- \Sabre\DAV\INode $node
+ \Sabre\DAV\INode $node,
) {
if (!($node instanceof File) && !($node instanceof Directory)) {
return;
}
- // need prefetch ?
- if ($node instanceof Directory
- && $propFind->getDepth() !== 0
- && !is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD))
- ) {
- $this->cacheDirectory($node);
- }
-
$propFind->handle(self::PROPERTY_NAME_COUNT, function () use ($node): int {
return $this->commentsManager->getNumberOfCommentsForObject('files', (string)$node->getId());
});