Skip to content

fix: rely on DB library to purge project cache after config updates#12749

Closed
ChiragAgg5k wants to merge 1 commit into
mainfrom
fix/project-config-stale-cache-after-write
Closed

fix: rely on DB library to purge project cache after config updates#12749
ChiragAgg5k wants to merge 1 commit into
mainfrom
fix/project-config-stale-cache-after-write

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

Removes the manual purgeCachedDocument('projects', ...) band-aids added in #12654 and fixes the underlying stale read-after-write at its source in utopia-php/database.

Background

Project config endpoints write the project document inside an endpoint-level withTransaction() (for lost-update safety) and are read back from the cached project document. updateDocument()'s "purge again after commit" guard only fired after the real COMMIT when the write owned the outermost transaction. Nested in a caller's transaction, that purge ran while still inside the transaction — before commit — so a concurrent reader could re-cache the pre-commit project. #12654 patched around it by purging the project cache again in each endpoint.

The proper fix lives in the DB library: utopia-php/database#910 defers every in-transaction cache purge until the outermost transaction commits. That closes the race for all callers, so the manual purges here are redundant.

Reproduced (real MariaDB + Redis, 16 concurrent readers, single writer): 40.6% → 0% stale reads after the library fix.

Changes

  • Removed the redundant purgeCachedDocument('projects', ...) from the 15 endpoints that write the project document directly (AuthMethods, OAuth2, Protocols, SMTP, Services, and 10 Policies).
  • Kept the purges in Platforms / Keys / DevKeys / Webhooks endpoints — those write child collections but invalidate the project's subQuery*-populated cache, which the library cannot purge automatically (not a DB relationship).
  • composer.json / composer.lock point utopia-php/database at the fix branch via a VCS repo.

Blocked on / merge order

Kept as draft until the library release is out — it must not merge against a dev branch.

The manual `purgeCachedDocument('projects', ...)` calls added after
project-config updates (#12654) worked around a stale read-after-write:
`updateDocument()`'s post-commit cache purge ran before the real COMMIT
when the write was nested inside an endpoint-level withTransaction(), so
a concurrent reader could re-cache the pre-commit project.

utopia-php/database now defers cache purges until the outermost
transaction commits (utopia-php/database#910), which fixes the race at
the source and makes these manual purges redundant. Remove them from the
endpoints that write the project document directly.

Kept the purges in Platforms/Keys/DevKeys/Webhooks endpoints: those write
child collections but invalidate the project's subquery-populated cache,
which the library cannot purge automatically.

Points composer at the dev branch pending the library release + tag.
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/project-config-stale-cache-after-write (after).

Metric Before After Change
🚀 Requests/sec 87.83 87.56 -0.3%
⏱️ Latency P50 134.77 ms 138.22 ms +2.6%
⏱️ Latency P95 577.25 ms 562.83 ms -2.5%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 138.22 562.83 5,858 87.56 -14.42
Account 293.44 3,816.62 404 6.57 +1,633.27
TablesDB 126.94 497.98 3,131 48.2 +8.14
Storage 117.1 539.19 1,515 23.83 +44.44
Functions 211.03 605.44 808 12.93 +25.56

Top API waits (after)

API request Max wait (ms)
account.logs.list 6,076.05
tablesdb.rows.create 5,016.95
functions.variables.get 4,951.78
tablesdb.rows.increment 1,653.09
storage.files.preview 1,457.72

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

🔄 PHP-Retry Summary

Flaky tests detected across commits:

Commit c65a584 - 2 flaky tests
Test Retries Total Time Details
FunctionsScheduleTest::testCreateScheduledExecution 1 125.00s Logs
FunctionsScheduleTest::testCreateScheduledAtExecution 1 128.36s Logs

@ChiragAgg5k ChiragAgg5k closed this Jul 1, 2026
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