File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -343,6 +343,15 @@ function downloadBatch(array $urls) {
343343 $ [if `process.env.API === "true" `]$
344344 if (isset ($ _REQUEST ["ls " ])) {
345345 $ info = [];
346+ $ [end]$
347+ $ [if `process.env.API === "true" && process.env.DOWNLOAD_COUNTER === "true" `]$
348+ // Get all counters in one call
349+ $ urls = array_map (fn ($ file ) => $ file ->url , $ sorted );
350+ $ all_counters = $ redis ->mget ($ urls );
351+ $ counters_map = array_combine ($ urls , $ all_counters );
352+ $ [end]$
353+ $ [if `process.env.API === "true" `]$
354+
346355 foreach ($ sorted as $ file ) {
347356 if ($ file ->name === ".. " ) continue ; // skip parent folder
348357 $ info [] = [
@@ -351,7 +360,7 @@ function downloadBatch(array $urls) {
351360 "type " => $ file ->is_dir ? "dir " : "file " ,
352361 "size " => intval ($ file ->size ),
353362 "modified " => $ file ->modified_date ,
354- "downloads " => $ {{`process.env.DOWNLOAD_COUNTER === "true" ? "intval( $ redis -> get ( $ file ->url ) )" : "0" `}}$
363+ "downloads " => $ {{`process.env.DOWNLOAD_COUNTER === "true" ? "intval( $ counters_map [ $ file ->url] ?? 0 )" : "0" `}}$
355364 ];
356365 }
357366 header ("Content-Type: application/json " );
You can’t perform that action at this time.
0 commit comments