mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-10-08 02:22:12 -03:00
feat(scanner): scan a single root and keep unreachable entries (#1108)
Refreshing had no way to say "scan only this drive": a user with three external
drives had to spin all of them up for every refresh, and switching a drive off
made the next refresh treat its whole library as deleted (rows pruned from the
memory cache and the SQLite cache, preview_url stripped on the next scroll).
Backend (py/services/model_scanner.py, py/config.py):
* ReconcileScope(roots, folder) + _reconcile_cache(scope=...): files inside the
scope reconcile normally, everything outside is neither re-read nor removed.
The folder half is plumbing for the sidebar entry in the next change.
* Path-level pruning guard: cached entries under a path this walk could not
read are kept and reported instead of removed. Sources: a configured root that
is not reachable (drive switched off while LM runs), a directory os.walk
failed to enter (permissions / I/O error / Windows junction to an offline
drive), and a known first-level symlink whose target is gone
(Config.iter_path_mappings()).
* The recorded folder list is unioned instead of replaced whenever the scan did
not verify every root, so a scoped scan cannot empty the sidebar.
* _reconcile_cache returns a summary (added / removed / repaired /
scanned_roots / skipped_roots / unavailable_paths / kept_unreachable),
exposed as ModelScanner.last_reconcile_summary, returned by
BaseModelService.scan_models() and broadcast in the completed WS payload.
* _root_display_labels(): set-aware labels ("G: loras", "usb/loras") grown
leftwards with real parent segments until unique, shared by the walk-progress
line and the roots API.
* GET /scan accepts repeated `roots` (400 for unknown roots, 400 combined with
full_rebuild=true); GET /roots gains root_details (label / reachable / cached
count) while `roots` stays a plain path list for existing callers.
* serve_preview: a 404 no longer clears the cached preview_url when the file's
own directory is unreachable - browsing the grid with a drive off used to
strip preview references from the persistent cache.
Frontend:
* Refresh ▾ gains a "Scan one folder" section listing the page's roots with
their cached counts; offline roots stay clickable and explain themselves; rows
are wired by delegation (new static/js/components/controls/ScanScopeMenu.js).
* A scoped scan reports "Scanned <root>: N new, M removed"; a scan that kept
entries reports "<N> models kept: <paths> not reachable".
* registerAPI() now injects the two cross-page passthroughs (fetchModelRoots and
an argument-forwarding refreshModels) so a page facade cannot drop them: the
first version rendered an empty menu and would have run a full refresh.
* createToastElement whitelists toast types, so a wrong `type` argument degrades
to the info style instead of rendering an unstyled box.
Verified in a sandbox instance with three roots: a scoped scan walks only the
requested root (progress roots=0/1, 240 files); a full refresh with one root
offline reports kept_unreachable=60 and leaves all 420 models cached; /roots
reports the offline root with its cached count. 3699 passed, 7 skipped;
frontend 1488 passed (148 files); vue widgets 96 passed.
This commit is contained in:
@@ -511,8 +511,9 @@ export class BaseModelApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
async refreshModels(fullRebuild = false) {
|
||||
async refreshModels(fullRebuild = false, { roots = null } = {}) {
|
||||
const abortController = new AbortController();
|
||||
const scopeRoots = Array.isArray(roots) ? roots.filter(Boolean) : [];
|
||||
const displayName = this.apiConfig.config.displayName;
|
||||
const singularName = this.apiConfig.config.singularName;
|
||||
const actionText = translate(
|
||||
@@ -600,6 +601,9 @@ export class BaseModelApiClient {
|
||||
|
||||
const url = new URL(this.apiConfig.endpoints.scan, window.location.origin);
|
||||
url.searchParams.append('full_rebuild', fullRebuild);
|
||||
for (const root of scopeRoots) {
|
||||
url.searchParams.append('roots', root);
|
||||
}
|
||||
|
||||
const response = await fetch(url, { signal: abortController.signal });
|
||||
|
||||
@@ -615,7 +619,7 @@ export class BaseModelApiClient {
|
||||
|
||||
resetAndReload(true);
|
||||
|
||||
showToast('toast.api.refreshComplete', { action: actionText }, 'success');
|
||||
this._showRefreshSummary(data, actionText, scopeRoots);
|
||||
} catch (error) {
|
||||
if (error.name === 'AbortError') {
|
||||
showToast('toast.api.operationCancelled', {}, 'info');
|
||||
@@ -632,6 +636,59 @@ export class BaseModelApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Report what a finished scan did.
|
||||
*
|
||||
* A scoped scan names the folder it scanned and how many models changed; a
|
||||
* scan that could not read part of its scope says so instead of silently
|
||||
* looking like "nothing found" (the entries are kept, not deleted).
|
||||
* @param {Object} summary - Scan response payload
|
||||
* @param {string} actionText - Localized "Refresh" / "Full rebuild"
|
||||
* @param {Array<string>} scopeRoots - Roots the scan was restricted to
|
||||
*/
|
||||
_showRefreshSummary(summary, actionText, scopeRoots = []) {
|
||||
const payload = summary || {};
|
||||
const scannedRoots = Array.isArray(payload.scanned_roots) ? payload.scanned_roots : [];
|
||||
const scopeLabel = scannedRoots.length ? scannedRoots.join(', ') : '';
|
||||
|
||||
if (scopeRoots.length && scopeLabel) {
|
||||
showToast(
|
||||
'toast.api.refreshCompleteScoped',
|
||||
{
|
||||
scope: scopeLabel,
|
||||
added: Number(payload.added || 0),
|
||||
removed: Number(payload.removed || 0),
|
||||
},
|
||||
'success'
|
||||
);
|
||||
} else {
|
||||
showToast('toast.api.refreshComplete', { action: actionText }, 'success');
|
||||
}
|
||||
|
||||
const keptCount = Number(payload.kept_unreachable || 0);
|
||||
if (keptCount > 0) {
|
||||
const unavailable = Array.isArray(payload.unavailable_paths)
|
||||
? payload.unavailable_paths
|
||||
: [];
|
||||
const skipped = Array.isArray(payload.skipped_roots) ? payload.skipped_roots : [];
|
||||
// Skipped roots already carry a short label; the remaining
|
||||
// unreadable folders only have a path.
|
||||
const names = (
|
||||
skipped.length
|
||||
? skipped.map(entry => entry?.label || entry?.path)
|
||||
: unavailable.map(entry => entry?.path)
|
||||
).filter(Boolean);
|
||||
showToast(
|
||||
'toast.api.refreshKeptUnreachable',
|
||||
{
|
||||
count: keptCount.toLocaleString(),
|
||||
paths: names.slice(0, 3).join(', ') || '—',
|
||||
},
|
||||
'info'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the shared fetch-progress WebSocket for scan progress updates.
|
||||
* Returns null when the connection cannot be established (silent fallback).
|
||||
|
||||
Reference in New Issue
Block a user