@@ -98,6 +98,7 @@ public function initialize(\Sabre\DAV\Server $server) {
9898 $ this ->server = $ server ;
9999 $ this ->server ->on ('propFind ' , [$ this , 'handleGetProperties ' ]);
100100 $ this ->server ->on ('propPatch ' , [$ this , 'handleUpdateProperties ' ]);
101+ $ this ->server ->on ('preloadProperties ' , [$ this , 'handlePreloadProperties ' ]);
101102 }
102103
103104 /**
@@ -153,6 +154,24 @@ private function getTags($fileId) {
153154 return null ;
154155 }
155156
157+ /**
158+ * Prefetches tags for a list of file IDs and caches the results
159+ *
160+ * @param array $fileIds List of file IDs to prefetch tags for
161+ * @return void
162+ */
163+ private function prefetchTagsForFileIds (array $ fileIds ) {
164+ $ tags = $ this ->getTagger ()->getTagsForObjects ($ fileIds );
165+ if ($ tags === false ) {
166+ // the tags API returns false on error...
167+ $ tags = [];
168+ }
169+
170+ foreach ($ fileIds as $ fileId ) {
171+ $ this ->cachedTags [$ fileId ] = $ tags [$ fileId ] ?? [];
172+ }
173+ }
174+
156175 /**
157176 * Updates the tags of the given file id
158177 *
@@ -203,22 +222,11 @@ public function handleGetProperties(
203222 )) {
204223 // note: pre-fetching only supported for depth <= 1
205224 $ folderContent = $ node ->getChildren ();
206- $ fileIds[] = (int ) $ node ->getId ();
225+ $ fileIds = [ (int ) $ node ->getId ()] ;
207226 foreach ($ folderContent as $ info ) {
208227 $ fileIds [] = (int ) $ info ->getId ();
209228 }
210- $ tags = $ this ->getTagger ()->getTagsForObjects ($ fileIds );
211- if ($ tags === false ) {
212- // the tags API returns false on error...
213- $ tags = [];
214- }
215-
216- $ this ->cachedTags = $ this ->cachedTags + $ tags ;
217- $ emptyFileIds = array_diff ($ fileIds , array_keys ($ tags ));
218- // also cache the ones that were not found
219- foreach ($ emptyFileIds as $ fileId ) {
220- $ this ->cachedTags [$ fileId ] = [];
221- }
229+ $ this ->prefetchTagsForFileIds ($ fileIds );
222230 }
223231
224232 $ isFav = null ;
@@ -274,4 +282,14 @@ public function handleUpdateProperties($path, PropPatch $propPatch) {
274282 return 200 ;
275283 });
276284 }
285+
286+ public function handlePreloadProperties (array $ nodes , array $ requestProperties ): void {
287+ if (
288+ !in_array (self ::FAVORITE_PROPERTYNAME , $ requestProperties , true ) &&
289+ !in_array (self ::TAGS_PROPERTYNAME , $ requestProperties , true )
290+ ) {
291+ return ;
292+ }
293+ $ this ->prefetchTagsForFileIds (array_map (fn ($ node ) => $ node ->getId (), $ nodes ));
294+ }
277295}
0 commit comments