@@ -94,6 +94,7 @@ public function initialize(\Sabre\DAV\Server $server) {
9494 $ this ->server = $ server ;
9595 $ this ->server ->on ('propFind ' , [$ this , 'handleGetProperties ' ]);
9696 $ this ->server ->on ('propPatch ' , [$ this , 'handleUpdateProperties ' ]);
97+ $ this ->server ->on ('preloadProperties ' , [$ this , 'handlePreloadProperties ' ]);
9798 }
9899
99100 /**
@@ -149,6 +150,27 @@ private function getTags($fileId) {
149150 return null ;
150151 }
151152
153+ /**
154+ * Prefetches tags for a list of file IDs and caches the results
155+ *
156+ * @param array $fileIds List of file IDs to prefetch tags for
157+ * @return void
158+ */
159+ private function prefetchTagsForFileIds (array $ fileIds ) {
160+ $ tags = $ this ->getTagger ()->getTagsForObjects ($ fileIds );
161+ if ($ tags === false ) {
162+ // the tags API returns false on error...
163+ $ tags = [];
164+ }
165+
166+ $ this ->cachedTags = $ this ->cachedTags + $ tags ;
167+ $ emptyFileIds = array_diff ($ fileIds , array_keys ($ tags ));
168+ // also cache the ones that were not found
169+ foreach ($ emptyFileIds as $ fileId ) {
170+ $ this ->cachedTags [$ fileId ] = [];
171+ }
172+ }
173+
152174 /**
153175 * Updates the tags of the given file id
154176 *
@@ -199,22 +221,11 @@ public function handleGetProperties(
199221 )) {
200222 // note: pre-fetching only supported for depth <= 1
201223 $ folderContent = $ node ->getChildren ();
202- $ fileIds[] = (int )$ node ->getId ();
224+ $ fileIds = [ (int )$ node ->getId ()] ;
203225 foreach ($ folderContent as $ info ) {
204226 $ fileIds [] = (int )$ info ->getId ();
205227 }
206- $ tags = $ this ->getTagger ()->getTagsForObjects ($ fileIds );
207- if ($ tags === false ) {
208- // the tags API returns false on error...
209- $ tags = [];
210- }
211-
212- $ this ->cachedTags = $ this ->cachedTags + $ tags ;
213- $ emptyFileIds = array_diff ($ fileIds , array_keys ($ tags ));
214- // also cache the ones that were not found
215- foreach ($ emptyFileIds as $ fileId ) {
216- $ this ->cachedTags [$ fileId ] = [];
217- }
228+ $ this ->prefetchTagsForFileIds ($ fileIds );
218229 }
219230
220231 $ isFav = null ;
@@ -270,4 +281,16 @@ public function handleUpdateProperties($path, PropPatch $propPatch) {
270281 return 200 ;
271282 });
272283 }
284+
285+ public function handlePreloadProperties (array $ nodes , array $ requestProperties ): void {
286+ if (
287+ !in_array (self ::FAVORITE_PROPERTYNAME , $ requestProperties , true ) &&
288+ !in_array (self ::TAGS_PROPERTYNAME , $ requestProperties , true )
289+ ) {
290+ return ;
291+ }
292+ $ this ->prefetchTagsForFileIds (array_map (function ($ node ) {
293+ return $ node ->getId ();
294+ }, $ nodes ));
295+ }
273296}
0 commit comments