Skip to content

Commit 0a79bc4

Browse files
committed
perf(caldav): also cache empty share arrays
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
1 parent 5262bac commit 0a79bc4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

apps/dav/lib/DAV/Sharing/Backend.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ public function deleteAllSharesByUser(string $principaluri): void {
116116
* @return list<array{href: string, commonName: string, status: int, readOnly: bool, '{http://owncloud.org/ns}principal': string, '{http://owncloud.org/ns}group-share': bool}>
117117
*/
118118
public function getShares(int $resourceId): array {
119+
/** @var list<array{href: string, commonName: string, status: int, readOnly: bool, '{http://owncloud.org/ns}principal': string, '{http://owncloud.org/ns}group-share': bool}>|null $cached */
119120
$cached = $this->shareCache->get((string)$resourceId);
120-
if ($cached) {
121+
if (is_array($cached)) {
121122
return $cached;
122123
}
123124

@@ -161,6 +162,23 @@ public function preloadShares(array $resourceIds): void {
161162
];
162163
$this->shareCache->set((string)$resourceId, $sharesByResource[$resourceId]);
163164
}
165+
166+
// Also remember resources with no shares to prevent superfluous (empty) queries later on
167+
foreach ($resourceIds as $resourceId) {
168+
$hasShares = false;
169+
foreach ($rows as $row) {
170+
if ((int)$row['resourceid'] === $resourceId) {
171+
$hasShares = true;
172+
break;
173+
}
174+
}
175+
176+
if ($hasShares) {
177+
continue;
178+
}
179+
180+
$this->shareCache->set((string)$resourceId, []);
181+
}
164182
}
165183

166184
/**

0 commit comments

Comments
 (0)