(folder, depthOverride, sourceId = '')
| 3174 | } |
| 3175 | |
| 3176 | function fetchFolderSummaryStats(folder, depthOverride, sourceId = '') { |
| 3177 | if (!folder) return Promise.resolve(null); |
| 3178 | if (isSlowRemoteSource(sourceId)) { |
| 3179 | return Promise.resolve(null); |
| 3180 | } |
| 3181 | |
| 3182 | const depthSetting = Number.isFinite(depthOverride) ? depthOverride : getFileListSummaryDepth(); |
| 3183 | const depth = Math.max(MIN_FILE_LIST_SUMMARY_DEPTH, Math.min(MAX_FILE_LIST_SUMMARY_DEPTH, depthSetting)); |
| 3184 | const depthKey = depth > 0 ? String(depth) : 'u'; |
| 3185 | const baseKey = folderCacheKey(folder, sourceId); |
| 3186 | const cacheKey = `${baseKey}::${depthKey}`; |
| 3187 | |
| 3188 | if (_folderSummaryCache.has(cacheKey)) { |
| 3189 | return _folderSummaryCache.get(cacheKey); |
| 3190 | } |
| 3191 | |
| 3192 | const depthParam = depth > 0 ? `&depth=${depth}` : ''; |
| 3193 | const sourceParam = sourceId ? `&sourceId=${encodeURIComponent(sourceId)}` : ''; |
| 3194 | const url = withBase(`/api/folder/isEmpty.php?folder=${encodeURIComponent(folder)}&deep=1${depthParam}${sourceParam}&t=${Date.now()}`); |
| 3195 | const p = _fetchJSONWithTimeout(url, 6000).then(data => { |
| 3196 | if (data && data.__fr_err) { |
| 3197 | _folderSummaryCache.delete(cacheKey); |
| 3198 | return null; |
| 3199 | } |
| 3200 | return data || null; |
| 3201 | }); |
| 3202 | |
| 3203 | _folderSummaryCache.set(cacheKey, p); |
| 3204 | return p; |
| 3205 | } |
| 3206 | |
| 3207 | function clearFolderSummaryCache(folder, sourceId = '') { |
| 3208 | if (!folder) return; |
no test coverage detected