Skip to content

fix(backend): invalidate public apps list cache on app visibility toggle (#3783) - #8594

Merged
kodjima33 merged 3 commits into
BasedHardware:mainfrom
ZachL111:zach/apps-visibility-cache-invalidation
Jun 30, 2026
Merged

kodjima33 merged 3 commits into
BasedHardware:mainfrom
ZachL111:zach/apps-visibility-cache-invalidation

Conversation

@ZachL111

@ZachL111 ZachL111 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Toggling an approved app's visibility (PATCH /v1/apps/{app_id}/change-visibility) did not refresh the public marketplace list cache, so making an app public did not surface it (and making it private kept showing it) until the list cache TTL expired. This addresses the app publishing/editing caching issue reported in #3783.

Root cause

The public approved-apps list is cached (get_public_approved_apps_data) and invalidated via invalidate_approved_apps_cache(). Every app mutation that changes public-list membership already calls it: approve_app, reject_app, delete_app, and update_app. change_app_visibility was the one exception. It updated the document and cleared the per-app cache (delete_app_cache_by_id) but never invalidated the list cache, so a visibility toggle was not reflected in the marketplace listing until the cache expired on its own (up to its TTL).

Fix

change_app_visibility now calls invalidate_approved_apps_cache() when the app is approved (the only case where it appears in the public list), mirroring delete_app. The per-app cache invalidation is unchanged. Unapproved apps are not in the public list, so their visibility toggle skips the list invalidation.

Testing

Added tests/unit/test_app_visibility_cache_invalidation.py (registered in test.sh): an approved app made public or private invalidates the list cache; an unapproved app does not, while the per-app cache is always cleared. Red-proven against the current head (the two approved-app cases fail without the fix). black clean.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Nice catch and clean fix, thanks @ZachL111 — crediting this to your work on #3783.

Verified the approach against the current source: change_app_visibility was the one app mutation that never invalidated the public approved-apps list cache, while every sibling (approve_app, reject_app, delete_app, update_app) already does. The if app.approved: guard mirrors delete_app exactly, which is the right call here — toggling an approved app's visibility changes its public-list membership in both directions (private→public adds it; public→private removes it), so unconditional invalidation when approved is correct. Skipping unapproved apps (which are never in the public list) is also correct.

Tests look good: the three cases cover the approved-public/approved-private invalidation paths plus the unapproved skip, and assert the per-app cache is always cleared. The red-proven claim and the meta-path-finder import-stubbing pattern both match existing repo conventions. CI is green.

Leaving a positive signal for a human maintainer to give this the final look before merge.

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @ZachL111 — nice catch and clean fix.

Root cause confirmed. change_app_visibility updated the DB and cleared the per-app cache but never invalidated the public approved-apps list cache, so an approved app's visibility toggle (public ↔ private) was not reflected in the marketplace list until the cache TTL expired. Every sibling mutation (approve_app, reject_app, update_app, delete_app) already invalidates that list cache — change_app_visibility was the sole exception.

The fix mirrors delete_app exactly: update_app_visibility_in_db → if app.approved: invalidate_approved_apps_cache() → delete_app_cache_by_id. The approved-only guard is the right call, since only approved apps appear in the public list; an unapproved app correctly skips the list invalidation while still clearing its per-app cache.

Tests cover the three meaningful cases (approved→public, approved→private, unapproved) and the harness correctly opts into process isolation via test.sh's sys.modules detection. All checks are green.

This looks ready for a maintainer merge. (Posting as a comment rather than a formal approval per the project's review automation policy; nothing action-blocking here.)

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Backend bug fix, CI green, scoped — merging (confidence 4/5).

@kodjima33
kodjima33 merged commit 2f1f05f into BasedHardware:main Jun 30, 2026
4 checks passed
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.

3 participants