Skip to content

Reduce redundant fields in apps list API responses#4233

Merged
beastoin merged 2 commits intomainfrom
fix/reduce-apps-list-cache-size
Jan 15, 2026
Merged

Reduce redundant fields in apps list API responses#4233
beastoin merged 2 commits intomainfrom
fix/reduce-apps-list-cache-size

Conversation

@beastoin
Copy link
Copy Markdown
Collaborator

@beastoin beastoin commented Jan 15, 2026

#4231

Reduces Redis cache size by filtering large fields (prompts, reviews, payment IDs, twitter) BEFORE caching. This fixes the root cause of #4215 where get_public_approved_apps_data cache consumed 25MB per entry, causing Redis bandwidth spikes to 400 MB/s during WebSocket connections.

deploy steps


This PR was drafted by AI on behalf of @beastoin

- Add to_reduced_dict() method to App model that excludes large/redundant fields
- Excludes: reviews, user_review, persona_prompt, chat_prompt, memory_prompt,
  payment_product_id, payment_price_id, payment_link_id, twitter
- Update all list endpoints to use to_reduced_dict() instead of model_dump()
- Affected endpoints: /v1/apps, /v1/approved-apps, /v1/apps/popular,
  /v2/apps, /v2/apps/search, capability groups responses

Fixes #4231

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively reduces the payload size for app list APIs by introducing a to_reduced_dict() method that excludes large and redundant fields. This is a great optimization that addresses the root cause of significant performance issues.

My main feedback is on the implementation within the v1 API endpoints in backend/routers/apps.py. The removal of response_model from these endpoints is a breaking change that weakens the API contract and bypasses FastAPI's validation and documentation features. I've left detailed comments suggesting the use of a dedicated Pydantic summary model (e.g., AppSummary) for these responses. This would maintain a strong API contract while still achieving the desired payload reduction.

The changes in the v2 endpoints and utility functions are well-implemented. Adopting the suggested changes for the v1 endpoints will make this solution more robust and maintainable.

Comment thread backend/routers/apps.py Outdated
Comment thread backend/routers/apps.py Outdated
Comment thread backend/routers/apps.py Outdated
@beastoin beastoin force-pushed the fix/reduce-apps-list-cache-size branch from e419595 to d62384f Compare January 15, 2026 04:53
- Add AppBaseModel with common list-view fields
- App now inherits from AppBaseModel, adding detail-only fields
- Add APP_REDUCE_EXCLUDE_FIELDS constant for consistency
- Add App.reduce_dict() static method for centralizing dict reduction logic
- Update caching functions to use App.reduce_dict() before Redis storage:
  - get_popular_apps()
  - get_available_apps()
  - get_approved_available_apps()
- Restore response_model=List[AppBaseModel] on list endpoints

This significantly reduces Redis cache size by excluding large fields:
- persona_prompt, chat_prompt, memory_prompt (large text)
- reviews, user_review (full review objects)
- payment_product_id, payment_price_id, payment_link_id
- twitter, email, money_made, usage_count

Fixes #4231

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@beastoin beastoin force-pushed the fix/reduce-apps-list-cache-size branch from d62384f to f5d3fb4 Compare January 15, 2026 05:00
@beastoin beastoin self-assigned this Jan 15, 2026
@beastoin beastoin merged commit 233ad8e into main Jan 15, 2026
1 check passed
@beastoin beastoin deleted the fix/reduce-apps-list-cache-size branch January 15, 2026 08:53
@beastoin
Copy link
Copy Markdown
Collaborator Author

reducing redis cache size by 60% and api response size by 25%

~ ll /tmp/omi_apps*
-rw-r--r--@ 1 beastoin wheel 10M Jan 15 16:20 /tmp/omi_apps_after.txt
-rw-r--r--@ 1 beastoin wheel 1.8M Jan 15 16:21 /tmp/omi_apps_api_after.txt
-rw-r--r--@ 1 beastoin wheel 2.7M Jan 15 15:51 /tmp/omi_apps_api.txt
-rw-r--r--@ 1 beastoin wheel 24M Jan 15 15:46 /tmp/omi_apps.txt

Glucksberg pushed a commit to Glucksberg/omi-local that referenced this pull request Apr 28, 2026
* Reduce redundant fields in apps list API responses

- Add to_reduced_dict() method to App model that excludes large/redundant fields
- Excludes: reviews, user_review, persona_prompt, chat_prompt, memory_prompt,
  payment_product_id, payment_price_id, payment_link_id, twitter
- Update all list endpoints to use to_reduced_dict() instead of model_dump()
- Affected endpoints: /v1/apps, /v1/approved-apps, /v1/apps/popular,
  /v2/apps, /v2/apps/search, capability groups responses

Fixes BasedHardware#4231

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Refactor App model with inheritance and reduce Redis cache size

- Add AppBaseModel with common list-view fields
- App now inherits from AppBaseModel, adding detail-only fields
- Add APP_REDUCE_EXCLUDE_FIELDS constant for consistency
- Add App.reduce_dict() static method for centralizing dict reduction logic
- Update caching functions to use App.reduce_dict() before Redis storage:
  - get_popular_apps()
  - get_available_apps()
  - get_approved_available_apps()
- Restore response_model=List[AppBaseModel] on list endpoints

This significantly reduces Redis cache size by excluding large fields:
- persona_prompt, chat_prompt, memory_prompt (large text)
- reviews, user_review (full review objects)
- payment_product_id, payment_price_id, payment_link_id
- twitter, email, money_made, usage_count

Fixes BasedHardware#4231

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant