From c28f4764628974f786a16a6accd3493e5eddbd8d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 19 May 2026 18:24:06 +1200 Subject: [PATCH] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- app/realtime.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/realtime.php b/app/realtime.php index 6839f7d40c..27b1e23aff 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -1086,13 +1086,19 @@ $server->onMessage(function (int $connection, string $message) use ($container, if (!empty($projectId) && $projectId !== 'console') { // Negative-cache race: if any prior code path queried projects:$projectId // before this project existed (e.g. a router probe during connection - // setup), the Database's shared cache may hold an empty result. HTTP - // worker creates the project via dbForPlatform which purges on write, - // but there's a window during which Realtime can re-populate a stale - // cache entry. Purge before reading to force a fresh adapter hit. - $database->purgeCachedDocument('projects', $projectId); + // setup), the Database's shared cache may hold an empty result. Try the + // cached read first, and only purge/retry when the first lookup reports + // not-found so the shared cache remains effective for normal traffic. + try { + $project = $authorization->skip(fn () => $database->getDocument('projects', $projectId)); + } catch (AppwriteException $e) { + if ($e->getCode() !== 404) { + throw $e; + } - $project = $authorization->skip(fn () => $database->getDocument('projects', $projectId)); + $database->purgeCachedDocument('projects', $projectId); + $project = $authorization->skip(fn () => $database->getDocument('projects', $projectId)); + } $database = getProjectDB($project); $database->setAuthorization($authorization);