@@ -9,7 +9,9 @@ export interface IMailingListToOnboard {
99 * Upsert mailing lists (public-inbox/lore) for a segment/integration and
1010 * seed their processing state so the mailing_list_integration worker picks
1111 * them up. Re-running with the same sourceUrl re-points the list at the
12- * given segment/integration without resetting its processing progress.
12+ * given segment/integration without resetting its processing progress. Any
13+ * of this integration's lists no longer present in `lists` are soft-deleted,
14+ * so the worker (which filters on "deletedAt" IS NULL) stops polling them.
1315 * @param qx - Query executor (should be transactional)
1416 * @param segmentId - Segment the lists belong to
1517 * @param integrationId - Integration these lists are onboarded under
@@ -43,6 +45,15 @@ export async function upsertMailingLists(
4345 SELECT id, 'pending', 2, '{}'::jsonb, NOW(), NOW()
4446 FROM upserted_list
4547 ON CONFLICT ("listId") DO NOTHING
48+ ),
49+ removed_lists AS (
50+ UPDATE mailinglist.lists
51+ SET "deletedAt" = NOW(), "updatedAt" = NOW()
52+ WHERE "integrationId" = $(integrationId)::uuid
53+ AND "deletedAt" IS NULL
54+ AND "sourceUrl" NOT IN (
55+ SELECT v."sourceUrl" FROM json_to_recordset($(lists)::json) AS v(name text, "sourceUrl" text)
56+ )
4657 )
4758 SELECT id FROM upserted_list
4859 ` ,
0 commit comments