MCPcopy Create free account
hub / github.com/error311/FileRise / fetchFolderCounts

Function fetchFolderCounts

public/js/folderManager.js:935–977  ·  view source on GitHub ↗
(folder)

Source from the content-addressed store, hash-verified

933 return sid ? `${sid}::${folder}` : folder;
934}
935async 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}
978function invalidateFolderCaches(folder) {
979 if (!folder) return;
980 const sourceId = getActiveSourceId();

Callers 3

ensureFolderIconFunction · 0.85
primeChildTogglesFunction · 0.85
loadFolderTreeFunction · 0.85

Calls 8

folderStatsCacheKeyFunction · 0.85
withBaseFunction · 0.85
getCountTimeoutMsFunction · 0.85
_runCountFunction · 0.85
setMethod · 0.80
getActiveSourceIdFunction · 0.70
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected