From d96804c9cf35a454a08d914f87739a1bf648e962 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 7 Jun 2026 10:53:44 +0300 Subject: [PATCH 1/6] Clean orphan data --- src/Appwrite/Platform/Tasks/ScheduleBase.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index 1213f78924..7cb03e0c73 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -280,6 +280,9 @@ abstract class ScheduleBase extends Action if ($resource->isEmpty()) { Console::error("Resource not found: projectId::{$schedule['projectId']} resourceId::{$schedule['resourceId']}"); unset($this->schedules[$sequence]); + + $dbForPlatform->deleteDocument('schedules', $schedule['$id']); + continue; } From 28cce233683a5a1916051366452602196a3da3b0 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 7 Jun 2026 10:55:43 +0300 Subject: [PATCH 2/6] Clean orphan data --- src/Appwrite/Platform/Tasks/ScheduleBase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index 7cb03e0c73..0d499f931e 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -279,10 +279,10 @@ abstract class ScheduleBase extends Action if ($resource->isEmpty()) { Console::error("Resource not found: projectId::{$schedule['projectId']} resourceId::{$schedule['resourceId']}"); - unset($this->schedules[$sequence]); - $dbForPlatform->deleteDocument('schedules', $schedule['$id']); + unset($this->schedules[$sequence]); + continue; } From 21bd4ef770262b02efcb1a3351c60429b3f66257 Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 7 Jun 2026 10:56:01 +0300 Subject: [PATCH 3/6] line --- src/Appwrite/Platform/Tasks/ScheduleBase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index 0d499f931e..c1bde979e8 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -282,7 +282,6 @@ abstract class ScheduleBase extends Action $dbForPlatform->deleteDocument('schedules', $schedule['$id']); unset($this->schedules[$sequence]); - continue; } From 93d46fe1b0ae365b1a41999123eb5486d5166fef Mon Sep 17 00:00:00 2001 From: fogelito Date: Sun, 7 Jun 2026 11:17:28 +0300 Subject: [PATCH 4/6] Use bulk --- src/Appwrite/Platform/Tasks/ScheduleBase.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index c1bde979e8..b09f806e73 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -244,6 +244,7 @@ abstract class ScheduleBase extends Action } // Only process updated/new schedules, not all schedules + $scheduleIdsToDelete = []; foreach ($updatedSequences as $sequence) { $schedule = $this->schedules[$sequence] ?? null; if ($schedule === null) { @@ -279,8 +280,7 @@ abstract class ScheduleBase extends Action if ($resource->isEmpty()) { Console::error("Resource not found: projectId::{$schedule['projectId']} resourceId::{$schedule['resourceId']}"); - $dbForPlatform->deleteDocument('schedules', $schedule['$id']); - + $scheduleIdsToDelete[] = $schedule['$id']; unset($this->schedules[$sequence]); continue; } @@ -288,6 +288,12 @@ abstract class ScheduleBase extends Action $this->schedules[$sequence]['resource'] = $resource; } + if (!empty($scheduleIdsToDelete)) { + $dbForPlatform->deleteDocuments('schedules', [ + Query::equal('$id', $scheduleIdsToDelete), + ]); + } + $lastSyncUpdate = $time; $duration = microtime(true) - $loadStart; $this->collectSchedulesTelemetryDuration->record($duration, ['initial' => $initialLoad, 'resourceType' => static::getSupportedResource()]); From 93c801caa670f0cdd9e5201ae927a37bcce62528 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 9 Jun 2026 09:22:05 +0300 Subject: [PATCH 5/6] wrap with go --- src/Appwrite/Platform/Tasks/ScheduleBase.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index b09f806e73..67ef04cce6 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -289,9 +289,11 @@ abstract class ScheduleBase extends Action } if (!empty($scheduleIdsToDelete)) { - $dbForPlatform->deleteDocuments('schedules', [ - Query::equal('$id', $scheduleIdsToDelete), - ]); + go(function () use ($dbForPlatform, $scheduleIdsToDelete) { + $dbForPlatform->deleteDocuments('schedules', [ + Query::equal('$id', $scheduleIdsToDelete), + ]); + }); } $lastSyncUpdate = $time; From f450ec0e7fa42c9d2146cc651fee2b3529350159 Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 9 Jun 2026 09:34:08 +0300 Subject: [PATCH 6/6] Update message --- src/Appwrite/Platform/Tasks/ScheduleBase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Appwrite/Platform/Tasks/ScheduleBase.php b/src/Appwrite/Platform/Tasks/ScheduleBase.php index 67ef04cce6..dfa33fad38 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleBase.php +++ b/src/Appwrite/Platform/Tasks/ScheduleBase.php @@ -289,6 +289,8 @@ abstract class ScheduleBase extends Action } if (!empty($scheduleIdsToDelete)) { + Console::info('Deleting ' . count($scheduleIdsToDelete) . ' orphaned schedules'); + go(function () use ($dbForPlatform, $scheduleIdsToDelete) { $dbForPlatform->deleteDocuments('schedules', [ Query::equal('$id', $scheduleIdsToDelete),