Skip to content

fix: useModels triggers unnecessary refresh=true scans on every mount #506

Description

@cswaney

Context

Follow-up to #467. useModels sends refresh=true unconditionally on every mount (loaders.js:14), which forces the backend to do a full filesystem scan + Hub metadata fetch on every tab open, focus event, and remount across three call sites (ModelsContainer, ServiceModal, NewJobModal). This was the fuel for the duplicate-row race fixed in #467, and it's independently wasteful backend work.

Why the default can safely change

  • The backend inserts into the model table on download success (asgi.py:2626-2700). Models downloaded through the app appear in the DB immediately — no scan required.
  • Without refresh=true, the endpoint returns DB contents. That's the correct source of truth for the common case.
  • The models page already has a refresh button — the one legitimate "force a scan" trigger already exists in the UI.

The only case the DB-only read misses is out-of-band additions (someone runs hf download directly on the cluster). Users who hit that case can press the refresh button on the models page.

Proposed change

In useModels (loaders.js:8-40):

  1. Drop refresh=true from the default SWR key and fetcher URLs.
  2. Add revalidateOnFocus: false and a modest dedupingInterval (e.g. 60s) to the SWR config.
  3. Expose a refresh() action that calls the refresh=true URL once and writes the result into the cache via mutate(fresh, { revalidate: false }).
  4. Wire the existing models-page refresh button to refresh() instead of plain mutate().

No changes needed to ServiceModal or NewJobModal — they get the DB-cached list, which is fast and correct.

Expected impact

  • Filesystem scans run only when a user explicitly presses the refresh button.
  • Modal opens over high-latency filesystems (SSH / Open OnDemand login node) become instant on second-and-later opens instead of always re-scanning.
  • Removes the last remaining trigger for the Race in get_models(refresh=true) creates duplicate Model rows #467 race pattern.

Verification

  • Open a modal twice in quick succession → only one network call, no scan on the second.
  • Tab-away-and-back → no scan.
  • Download a model through the app → appears in modal without pressing refresh.
  • Press refresh button on models page → forces scan, cache updates everywhere.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions