Skip to content

Commit eb34ddb

Browse files
authored
Merge pull request #54438 from nextcloud/perf/caldav/cache-empty-shares-when-preloading
perf(caldav): also cache empty share arrays
2 parents 9001ae2 + 0a79bc4 commit eb34ddb

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
@@ -131,8 +131,9 @@ public function deleteAllSharesByUser(string $principaluri): void {
131131
* @return list<array{href: string, commonName: string, status: int, readOnly: bool, '{http://owncloud.org/ns}principal': string, '{http://owncloud.org/ns}group-share': bool}>
132132
*/
133133
public function getShares(int $resourceId): array {
134+
/** @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 */
134135
$cached = $this->shareCache->get((string)$resourceId);
135-
if ($cached) {
136+
if (is_array($cached)) {
136137
return $cached;
137138
}
138139

@@ -176,6 +177,23 @@ public function preloadShares(array $resourceIds): void {
176177
];
177178
$this->shareCache->set((string)$resourceId, $sharesByResource[$resourceId]);
178179
}
180+
181+
// Also remember resources with no shares to prevent superfluous (empty) queries later on
182+
foreach ($resourceIds as $resourceId) {
183+
$hasShares = false;
184+
foreach ($rows as $row) {
185+
if ((int)$row['resourceid'] === $resourceId) {
186+
$hasShares = true;
187+
break;
188+
}
189+
}
190+
191+
if ($hasShares) {
192+
continue;
193+
}
194+
195+
$this->shareCache->set((string)$resourceId, []);
196+
}
179197
}
180198

181199
/**

0 commit comments

Comments
 (0)