Skip to content

Commit 648d187

Browse files
committed
patch archived tools events
1 parent 5ba1df2 commit 648d187

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

app/api/cron/sync-health/route.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,16 @@ export async function GET(request: Request) {
157157
}
158158
}
159159

160-
// Archived transition (previously not archived → now archived)
160+
// Archived transition — only fire once, even if prevSnapshot is absent
161161
const wasArchived = prevSnapshot?.archived ?? false;
162-
if (!wasArchived && ghData.archived) {
162+
const { count: existingArchiveCount } = ghData.archived
163+
? await db
164+
.from("tool_events")
165+
.select("id", { count: "exact", head: true })
166+
.eq("tool_id", tool.id)
167+
.eq("type", "archived_detected")
168+
: { count: 0 };
169+
if (!wasArchived && ghData.archived && !existingArchiveCount) {
163170
const { error: eventError } = await db.from("tool_events").insert({
164171
tool_id: tool.id,
165172
type: "archived_detected",

0 commit comments

Comments
 (0)