Comfy-Org / Comfy-Org/ComfyUI_frontend

Refactor 3D asset preview fetch to use store-level caching and eliminate N+1 API calls

Open
#10,014 0 comments 0 reactions 1 assignee Claimed by @jtydhr88 View on GitHub
area:3d perf:speed
Dominant language
TypeScript
Stars
2k
Forks
699
Avg merge
1d 7h
Merged PRs (30d)
490

Description

## Summary

In the 3D thumbnail inline rendering feature (introduced in PR #9471), every visible 3D asset card independently fires `GET /assets?name_contains=X` via `findServerPreviewUrl`, and `persistThumbnail` (Media3DTop.vue) calls `fetchAssetsByName` again for the same name. With N visible cards this results in 2N redundant requests.

## Problem

- Each `Media3DTop` component calls `fetchAssetsByName` in `src/platform/assets/utils/assetPreviewUtil.ts` independently.
- No deduplication or caching is applied across cards for the same asset name.
- `persistThumbnail` in `Media3DTop.vue` (line 83) also calls `fetchAssetsByName` again for the same name, doubling the request count.

## Suggested Approach

Move the asset-by-name lookup into a shared store or composable with caching:

- **`assetsStore.ts`** — use the existing category-based cache pattern (`modelStateByCategory`) to store and reuse asset records by name.
- **`modelStore.ts`** — use the `ResourceState` pattern to short-circuit duplicate loads for the same resource.
- **`useCachedRequest` composable** — provides deduplication with abort support for in-flight requests.

## References

- PR: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9471
- Review comment: https://github.com/Comfy-Org/ComfyUI_frontend/pull/9471#discussion_r2938399178
- Requested by: @christian-byrne

┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-10014-Refactor-3D-asset-preview-fetch-to-use-store-level-caching-and-eliminate-N-1-API-call-3256d73d36508178a007ecd682ee36be) by [Unito](https://www.unito.io)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.