Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api/zdrcleaner): clear dr_clean_by in batches of 100

mogery7d6264f11c72
diff --git a/apps/api/src/controllers/v0/admin/zdrcleaner.ts b/apps/api/src/controllers/v0/admin/zdrcleaner.ts
index 504094501..687bf7b8d 100644
--- a/apps/api/src/controllers/v0/admin/zdrcleaner.ts
+++ b/apps/api/src/controllers/v0/admin/zdrcleaner.ts
@@ -35,7 +35,7 @@ async function cleanUpRequests(specificTeamId: string | null, _logger: Logger) {
);
if (error) {
- logger.error("Error calling get_zdr_cleanup_batch RPC", { error });
+ logger.error("Error calling get_zdr_cleanup_batch RPC", { error, i });
throw error;
}
@@ -94,21 +94,25 @@ async function cleanUpRequests(specificTeamId: string | null, _logger: Logger) {
}
if (fullyCleanedRequests.length > 0) {
- try {
- await supabase_service
- .from("requests")
- .update({
- dr_clean_by: null,
- })
- .in("id", fullyCleanedRequests)
- .throwOnError();
-
- logger.info(`Cleaned up ${fullyCleanedRequests.length} requests`);
- } catch (error) {
- logger.error(`Error clearing dr_clean_by on requests`, {
- error,
- requestCount: fullyCleanedRequests.length,
- });
+ // Process in batches of 100 to deal with URL limits on PostgREST
+ for (let i = 0; i < fullyCleanedRequests.length; i += 100) {
+ const batch = fullyCleanedRequests.slice(i, i + 100);
+ try {
+ await supabase_service
+ .from("requests")
+ .update({
+ dr_clean_by: null,
+ })
+ .in("id", batch)
+ .throwOnError();
+
+ logger.info(`Cleaned up ${fullyCleanedRequests.length} requests`);
+ } catch (error) {
+ logger.error(`Error clearing dr_clean_by on requests`, {
+ error,
+ requestCount: fullyCleanedRequests.length,
+ });
+ }
}
}
}