fix(helpers): add TTL cache to dir_size_gb to prevent blocking rglob walks#950
Conversation
Lightheartdevs
left a comment
There was a problem hiding this comment.
TTL cache is the right shape for dir_size_gb. Reviewed the implementation:
- 60s TTL is reasonable — dashboard polls at ~5s intervals so this cuts rglob walks by an order of magnitude.
invalidate_dir_size_cache()correctly called aftershutil.rmtreeinpurge_extension_dataso the next poll doesn't return stale size.clear_dir_size_cache()is a nice escape hatch but I didn't see it called anywhere — consider adding it to_clear_settings_cachesif settings changes can move data dirs.
Minor note: the cache uses path.resolve() as key — good because it canonicalizes symlinks, but beware if callers pass relative paths from different cwds during a single process lifetime. Current callers all pass absolute paths, so fine for now.
The unrelated update-script-path resolution in routers/updates.py is a small bonus cleanup (collapses a confusing nested conditional). Ship.
The merge-base changed after approval.
Lightheartdevs
left a comment
There was a problem hiding this comment.
Re-submitting — prior approval review was dismissed (likely by an automation). TTL cache + invalidation pattern is correct, tests look good, 60s TTL is sensible for dashboard polling cadence. Details in the dismissed review.
The merge-base changed after approval.
b7fa750 to
99dc8a0
Compare
Summary
dir_size_gb()usespath.rglob("*")which recursively walks every file in a directory tree — on large model directories (tens of GB, thousands of files) this blocks the request thread on every callinvalidate_dir_size_cache()and wired it intopurge_extension_dataso the cache stays accurate after mutationsTest plan
/api/services/resourcesmultiple times within 60s — second call should return instantly without re-walking disk/api/extensions/{id}/data— subsequent resource calls should reflect the freed spacedir_size_gb, so no test changes needed)