agrs-sequelize-sdk 1.4.43 → 1.4.44

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.
@@ -292,6 +292,25 @@ module.exports = (sequelize, DataTypes) => {
292
292
  {
293
293
  fields: ["createdAt"],
294
294
  },
295
+ // Partial index mirroring the V2 side (idx_v2_awaiting_by_feed_campaign).
296
+ // The hourly Tarzo reconciler runs the SAME awaiting-materialization
297
+ // WHERE clause against both V1 and V2 (dual-write parity). Without this
298
+ // index the V1 UPDATE seq-scans 15.8M rows / 11GB and hits the 60s
299
+ // statement_timeout (verified in prod 2026-07-19: 207s EXPLAIN).
300
+ //
301
+ // Composite (feed_campaign_id, createdAt DESC) covers both:
302
+ // - step 2/5 join key (rfc.AGRS_CID = l.feed_campaign_id)
303
+ // - step 3/5 stale-age filter (l.createdAt < now() - 6h)
304
+ //
305
+ // Equality predicate — LIKE would be ignored by the planner (proven
306
+ // 2026-07-19). Self-pruning: rows drop out on COMPLETED/FAILED flip.
307
+ {
308
+ name: "idx_v1_awaiting_by_feed_campaign",
309
+ fields: ["feed_campaign_id", { name: "createdAt", order: "DESC" }],
310
+ where: sequelize.literal(
311
+ `status = 'IN_PROGRESS' AND (details->>'ai_stage') = 'tarzo_awaiting_materialization'`
312
+ ),
313
+ },
295
314
  ],
296
315
  }
297
316
  );
@@ -316,6 +316,26 @@ module.exports = (sequelize, DataTypes) => {
316
316
  `status = 'IN_PROGRESS' AND (details->>'ai_stage') = 'tarzo_awaiting_materialization'`
317
317
  ),
318
318
  },
319
+ // Partial index for the ai_campaign_queue backfill query in step 2/5
320
+ // (completeAdoptedAwaitingLogs's third UPDATE). After the awaiting log
321
+ // flips to COMPLETED, ai_stage becomes 'tarzo_materialized_and_adopted'
322
+ // and the queue's facebook_campaign_id gets backfilled by joining V2
323
+ // to ai_campaign_queue via process_id.
324
+ //
325
+ // Without this, the query bitmap-scans by status='COMPLETED' (returns
326
+ // 1.2M rows), then filters ai_stage in memory (rejects 1.18M) → 175s
327
+ // seq scan, 60s timeout in prod (verified 2026-07-19).
328
+ //
329
+ // Composite (process_id, feed_campaign_id) supports both the join to
330
+ // ai_campaign_queue.creation_logs_process_id AND the further join to
331
+ // rsoc_feed_campaigns.AGRS_CID.
332
+ {
333
+ name: "idx_v2_adopted_by_process",
334
+ fields: ["process_id", "feed_campaign_id"],
335
+ where: sequelize.literal(
336
+ `status = 'COMPLETED' AND (details->>'ai_stage') = 'tarzo_materialized_and_adopted'`
337
+ ),
338
+ },
319
339
  ],
320
340
  }
321
341
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agrs-sequelize-sdk",
3
- "version": "1.4.43",
3
+ "version": "1.4.44",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "start": "node index.js",