Reduce redundant fields in apps list API responses#4233
Conversation
- 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>
There was a problem hiding this comment.
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.
e419595 to
d62384f
Compare
- 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>
d62384f to
f5d3fb4
Compare
|
reducing redis cache size by 60% and api response size by 25% ~ ll /tmp/omi_apps* |
* 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>
#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_datacache 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