@hogsend/engine 0.58.0 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -11
- package/src/buckets/check-membership.ts +6 -0
- package/src/index.ts +16 -0
- package/src/journeys/execute-journey-run.ts +83 -1
- package/src/lib/contacts.ts +114 -0
- package/src/lib/ingestion.ts +9 -0
- package/src/lib/preferences.ts +39 -2
- package/src/lib/tracked.ts +31 -0
- package/src/routes/admin/bulk.ts +4 -0
- package/src/routes/admin/index.ts +2 -0
- package/src/routes/admin/maintenance.ts +210 -0
- package/src/routes/admin/preferences.ts +9 -1
- package/src/routes/lists/index.ts +5 -0
- package/src/worker.ts +20 -0
- package/src/workflows/backfill-contact-id.ts +771 -0
- package/src/workflows/bucket-backfill.ts +9 -1
- package/src/workflows/bucket-reconcile.ts +4 -0
|
@@ -229,10 +229,17 @@ async function backfillJoins(opts: {
|
|
|
229
229
|
// contacts row).
|
|
230
230
|
const resolvedKey = contactKeySql();
|
|
231
231
|
const chunkContacts = await db
|
|
232
|
-
.select({ userKey: resolvedKey, email: contacts.email })
|
|
232
|
+
.select({ userKey: resolvedKey, email: contacts.email, id: contacts.id })
|
|
233
233
|
.from(contacts)
|
|
234
234
|
.where(and(inArray(resolvedKey, chunk), isNull(contacts.deletedAt)));
|
|
235
235
|
const emailByUser = new Map(chunkContacts.map((c) => [c.userKey, c.email]));
|
|
236
|
+
// PRD 04 dual-write: the SAME already-issued per-chunk read carries the row
|
|
237
|
+
// id, so stamping `contact_id` costs one extra selected column and zero
|
|
238
|
+
// extra queries. A chunk key with no live contacts row (a membership keyed
|
|
239
|
+
// on a since-deleted / never-minted subject) simply stamps NULL.
|
|
240
|
+
const contactIdByUser = new Map(
|
|
241
|
+
chunkContacts.map((c) => [c.userKey, c.id]),
|
|
242
|
+
);
|
|
236
243
|
|
|
237
244
|
// Fix A: entryCount = 1 + prior memberships for each (user, bucket), the
|
|
238
245
|
// same monotonic ordinal the live join computes (check-membership.ts). On a
|
|
@@ -300,6 +307,7 @@ async function backfillJoins(opts: {
|
|
|
300
307
|
// Historical dwell anchor where derivable; NULL otherwise (→ enteredAt).
|
|
301
308
|
dwellAnchorAt: anchorByUser.get(userId) ?? null,
|
|
302
309
|
lastEvaluatedAt: new Date(),
|
|
310
|
+
contactId: contactIdByUser.get(userId) ?? null,
|
|
303
311
|
}));
|
|
304
312
|
|
|
305
313
|
const result = await db
|
|
@@ -1241,6 +1241,10 @@ async function reconcileJoinOne(opts: {
|
|
|
1241
1241
|
expiresAt: computeExpiresAt(bucket),
|
|
1242
1242
|
maxDwellAt: computeMaxDwellAt(bucket),
|
|
1243
1243
|
lastEvaluatedAt: new Date(),
|
|
1244
|
+
// PRD 04 dual-write — `contactId` is already a param of this function (the
|
|
1245
|
+
// cron reads it off the same contacts row it took userId/email from), so
|
|
1246
|
+
// this is zero new queries. `undefined` stamps NULL.
|
|
1247
|
+
contactId: contactId ?? null,
|
|
1244
1248
|
})
|
|
1245
1249
|
.onConflictDoNothing()
|
|
1246
1250
|
.returning({ id: bucketMemberships.id });
|