fix(ingest): an archived game must not keep the next match (#258)
ci / rust (push) Successful in 10m17s
ci / typescript (push) Successful in 14m27s

fix(ingest): an archived game must not keep the next match (#258)
This commit was merged in pull request #258.
This commit is contained in:
spark committed 2026-11-08 14:10:40 +00:00
1 parent fc2f9bc652
commit d5ee4dbd5a
4 files changed
+19 -5

No files matched your search

+3 -1
View File
@@ -400,10 +400,12 @@ export class IngestService {
if (!requested) return undefined;
const event = await this.deps.db.event.findFirst({
where: { id: requested, organizationId },
select: { ingestFrom: true, ingestUntil: true },
select: { ingestFrom: true, ingestUntil: true, archivedAt: true },
});
if (!event) return undefined;
if (at < event.ingestFrom || at > event.ingestUntil) return undefined;
// Put away, and another open event covers this time (the windows overlap): the pin must not keep the next match.
if (event.archivedAt && (await this.routeToEvent(organizationId, userId, at))) return undefined;
if (!(await this.sameSession(requested, userId, at))) return undefined;
return requested;
}
+8
View File
@@ -18,6 +18,14 @@ export async function joinedEvent(db: Db, eventId: string, ids: string[]): Promi
}
if ((event.autopilot as { enabled?: boolean } | null)?.enabled === true) {
await db.photo.updateMany({ where: { id: { in: ids }, status: "READY", source: { not: "CLOUD" }, autopilotStatus: "NONE" }, data: { autopilotStatus: "PENDING" } });
// Already read on the event they left: decide them again here, without running the crop a second time.
await db.$executeRaw`
UPDATE photos
SET autopilot = (autopilot::jsonb - 'curated' - 'chosen' - 'gallery')
WHERE id = ANY(${ids}::uuid[])
AND autopilot_status = 'DONE'
AND jsonb_typeof(autopilot::jsonb) = 'object'
`;
}
for (const id of ids) await applyRename(db, id);
}
+4 -2
View File
@@ -105,8 +105,10 @@ export function eventForArrival(pinnedId: string | null, events: RoutedEvent[],
if (!pinnedId) return routeLocally(events, at);
const pinned = events.find((e) => e.id === pinnedId);
if (!pinned) {
// Agenda cache miss: keep the open pin so USB/FTP does not dump live shots into Sem evento.
return pinnedId;
// Not in the open list: archived or deleted. Another open event that covers this time gets the photo.
// An empty list has not loaded yet — keep the pin so a live card is not dropped in the inbox.
const routed = events.length ? routeLocally(events, at) : null;
return routed ?? pinnedId;
}
if (pinned.archivedAt) return routeLocally(events, at);
const t = Date.parse(at);
+4 -2
View File
@@ -126,8 +126,10 @@ describe("photos arriving on this computer", () => {
// No capture time: keep the pin (USB already filtered by the card clock; server keeps the named folder too).
expect(eventForArrival("braga", events, null)).toBe("braga");
expect(eventForArrival(null, events, null)).toBeNull();
// Cache miss for the pin id: keep it (do not dump into Sem evento); archived pins fall through to the clock.
expect(eventForArrival("missing", events, "2026-10-10T15:30:00Z")).toBe("missing");
// A pin that is not in the open list was archived. An empty list has not loaded: keep the pin.
expect(eventForArrival("missing", events, "2026-10-10T15:30:00Z")).toBe("other");
expect(eventForArrival("missing", [], "2026-10-10T15:30:00Z")).toBe("missing");
expect(eventForArrival("missing", events, "2026-09-03T15:00:00Z")).toBe("missing");
expect(eventForArrival("braga", [{ ...events[0]!, archivedAt: "2026-10-10T00:00:00Z" }, events[1]!], "2026-10-10T15:30:00Z")).toBe("other");
});