(folder)
| 933 | return sid ? `${sid}::${folder}` : folder; |
| 934 | } |
| 935 | async function fetchFolderCounts(folder) { |
| 936 | const sourceId = getActiveSourceId(); |
| 937 | const key = folderStatsCacheKey(folder, sourceId); |
| 938 | if (_folderCountCache.has(key)) return _folderCountCache.get(key); |
| 939 | if (_inflightCounts.has(key)) return _inflightCounts.get(key); |
| 940 | if (_sharedFolderStatsCache.has(key)) { |
| 941 | const cached = _sharedFolderStatsCache.get(key); |
| 942 | _folderCountCache.set(key, cached); |
| 943 | return cached; |
| 944 | } |
| 945 | if (_sharedFolderStatsInflight.has(key)) { |
| 946 | const inflight = _sharedFolderStatsInflight.get(key); |
| 947 | _inflightCounts.set(key, inflight); |
| 948 | inflight.finally(() => { |
| 949 | if (_inflightCounts.get(key) === inflight) _inflightCounts.delete(key); |
| 950 | }); |
| 951 | return inflight; |
| 952 | } |
| 953 | const sourceParam = sourceId ? `&sourceId=${encodeURIComponent(sourceId)}` : ''; |
| 954 | const url = withBase(`/api/folder/isEmpty.php?folder=${encodeURIComponent(folder)}${sourceParam}&t=${Date.now()}`); |
| 955 | const timeoutMs = getCountTimeoutMs(sourceId); |
| 956 | const p = _runCount(url, timeoutMs).then(data => { |
| 957 | const payload = (data && !data.__fr_err) ? data : { folders: 0, files: 0 }; |
| 958 | const stillLocal = _inflightCounts.get(key) === p; |
| 959 | const stillShared = _sharedFolderStatsInflight.get(key) === p; |
| 960 | if (stillLocal) _inflightCounts.delete(key); |
| 961 | if (stillShared) _sharedFolderStatsInflight.delete(key); |
| 962 | if (data && data.__fr_err) { |
| 963 | return { folders: 0, files: 0, __fr_err: 1 }; |
| 964 | } |
| 965 | if (stillLocal) _folderCountCache.set(key, payload); |
| 966 | if (stillShared) _sharedFolderStatsCache.set(key, payload); |
| 967 | return payload; |
| 968 | }).catch(() => { |
| 969 | if (_inflightCounts.get(key) === p) _inflightCounts.delete(key); |
| 970 | if (_sharedFolderStatsInflight.get(key) === p) _sharedFolderStatsInflight.delete(key); |
| 971 | return { folders: 0, files: 0, __fr_err: 1 }; |
| 972 | }); |
| 973 | |
| 974 | _inflightCounts.set(key, p); |
| 975 | _sharedFolderStatsInflight.set(key, p); |
| 976 | return p; |
| 977 | } |
| 978 | function invalidateFolderCaches(folder) { |
| 979 | if (!folder) return; |
| 980 | const sourceId = getActiveSourceId(); |
no test coverage detected