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

Function fetchFolderStats

public/js/fileListView.js:3136–3174  ·  view source on GitHub ↗
(folder, sourceId = '')

Source from the content-addressed store, hash-verified

3134}
3135
3136function fetchFolderStats(folder, sourceId = '') {
3137 if (!folder) return Promise.resolve(null);
3138 if (isSlowRemoteSource(sourceId)) return Promise.resolve(null);
3139
3140 const key = folderCacheKey(folder, sourceId);
3141 if (_folderStatsCache.has(key)) {
3142 return Promise.resolve(_folderStatsCache.get(key));
3143 }
3144 if (_folderStatsInflight.has(key)) {
3145 return _folderStatsInflight.get(key);
3146 }
3147
3148 const sourceParam = sourceId ? `&sourceId=${encodeURIComponent(sourceId)}` : '';
3149 const url = withBase(`/api/folder/isEmpty.php?folder=${encodeURIComponent(folder)}${sourceParam}&t=${Date.now()}`);
3150 const timeoutMs = getFolderStatsTimeout(sourceId);
3151 const p = _runFolderStats(url, timeoutMs).then(data => {
3152 const payload = (data && !data.__fr_err) ? data : { folders: 0, files: 0 };
3153 const stillInflight = _folderStatsInflight.get(key) === p;
3154 if (stillInflight) {
3155 _folderStatsInflight.delete(key);
3156 }
3157 // If this was a transient network/server failure, don't poison the cache.
3158 if (data && data.__fr_err) {
3159 return payload;
3160 }
3161 if (stillInflight) {
3162 _folderStatsCache.set(key, payload);
3163 }
3164 return payload;
3165 }).catch(() => {
3166 if (_folderStatsInflight.get(key) === p) {
3167 _folderStatsInflight.delete(key);
3168 }
3169 return { folders: 0, files: 0 };
3170 });
3171
3172 _folderStatsInflight.set(key, p);
3173 return p;
3174}
3175
3176function fetchFolderSummaryStats(folder, depthOverride, sourceId = '') {
3177 if (!folder) return Promise.resolve(null);

Callers 4

fillHoverPreviewForRowFunction · 0.85
attachStripIconAsyncFunction · 0.85
injectInlineFolderRowsFunction · 0.85

Calls 8

isSlowRemoteSourceFunction · 0.85
folderCacheKeyFunction · 0.85
withBaseFunction · 0.85
getFolderStatsTimeoutFunction · 0.85
_runFolderStatsFunction · 0.85
setMethod · 0.80
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected