@secondlayer/subgraphs 3.14.1 → 3.14.3

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.
@@ -520,21 +520,22 @@ class SubgraphContext {
520
520
  "_tx_id",
521
521
  "_created_at"
522
522
  ];
523
- const valuesList = Array.from(batch.rows.values()).map((r) => {
524
- const vals = [
523
+ if (this.journal) {
524
+ statements.push(this.journalCaptureSQL(batch.table, batch.keyCols, Array.from(batch.rows.values()).map((r) => batch.keyCols.map((k) => escapeLiteral(r.keys[k])))));
525
+ }
526
+ for (const r of batch.rows.values()) {
527
+ const keyPred = batch.keyCols.map((k) => `"${k}" = ${escapeLiteral(r.keys[k])}`).join(" AND ");
528
+ const updSet = batch.deltaCols.map((c) => `"${c}" = COALESCE("${c}", 0) + (${String(r.deltas[c] ?? 0n)})`).join(", ");
529
+ statements.push(`UPDATE ${qualifiedTable} SET ${updSet} WHERE ${keyPred}`);
530
+ const insertVals = [
525
531
  ...batch.keyCols.map((k) => escapeLiteral(r.keys[k])),
526
532
  ...batch.deltaCols.map((c) => String(r.deltas[c] ?? 0n)),
527
533
  escapeLiteral(r.meta.blockHeight),
528
534
  escapeLiteral(r.meta.txId),
529
535
  "NOW()"
530
536
  ];
531
- return `(${vals.join(", ")})`;
532
- }).join(", ");
533
- const setClauses = batch.deltaCols.map((c) => `"${c}" = COALESCE("${batch.table}"."${c}", 0) + EXCLUDED."${c}"`);
534
- if (this.journal) {
535
- statements.push(this.journalCaptureSQL(batch.table, batch.keyCols, Array.from(batch.rows.values()).map((r) => batch.keyCols.map((k) => escapeLiteral(r.keys[k])))));
537
+ statements.push(`INSERT INTO ${qualifiedTable} (${cols.map((c) => `"${c}"`).join(", ")}) ` + `SELECT ${insertVals.join(", ")} ` + `WHERE NOT EXISTS (SELECT 1 FROM ${qualifiedTable} WHERE ${keyPred})`);
536
538
  }
537
- statements.push(`INSERT INTO ${qualifiedTable} (${cols.map((c) => `"${c}"`).join(", ")}) VALUES ${valuesList} ` + `ON CONFLICT (${batch.keyCols.map((k) => `"${k}"`).join(", ")}) DO UPDATE SET ${setClauses.join(", ")}`);
538
539
  incBatch = null;
539
540
  incBatchKey = "";
540
541
  };
@@ -1335,6 +1336,7 @@ import { resolveTraitContractIds } from "@secondlayer/shared/db/queries/contract
1335
1336
  import { advanceOperationCursor } from "@secondlayer/shared/db/queries/subgraph-operations";
1336
1337
  import {
1337
1338
  isByoSubgraph,
1339
+ recordLiveProgress,
1338
1340
  recordSubgraphProcessed,
1339
1341
  resolveSubgraphDb,
1340
1342
  updateSubgraphStatus
@@ -2029,7 +2031,7 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
2029
2031
  result.matched = matched.length;
2030
2032
  if (matched.length === 0) {
2031
2033
  if (!opts?.skipProgressUpdate) {
2032
- await updateSubgraphStatus(targetDb, subgraphName, "active", blockHeight);
2034
+ await recordLiveProgress(targetDb, subgraphName, blockHeight);
2033
2035
  }
2034
2036
  return result;
2035
2037
  }
@@ -2052,8 +2054,11 @@ async function processBlock(subgraph, subgraphName, blockHeight, opts) {
2052
2054
  const applyProgress = async (tx, rr) => {
2053
2055
  if (opts?.skipProgressUpdate)
2054
2056
  return;
2055
- const status = rr.errors > 0 && rr.processed === 0 ? "error" : "active";
2056
- await updateSubgraphStatus(tx, subgraphName, status, blockHeight);
2057
+ if (rr.errors > 0 && rr.processed === 0) {
2058
+ await updateSubgraphStatus(tx, subgraphName, "error", blockHeight);
2059
+ } else {
2060
+ await recordLiveProgress(tx, subgraphName, blockHeight);
2061
+ }
2057
2062
  if (rr.processed > 0 || rr.errors > 0) {
2058
2063
  const lastError = rr.errors > 0 ? `${rr.errors} error(s) at block ${blockHeight}` : undefined;
2059
2064
  await recordSubgraphProcessed(tx, subgraphName, rr.processed, rr.errors, lastError);
@@ -2427,5 +2432,5 @@ export {
2427
2432
  catchUpSubgraph
2428
2433
  };
2429
2434
 
2430
- //# debugId=8C07C6332915209664756E2164756E21
2435
+ //# debugId=055B56DE319F504964756E2164756E21
2431
2436
  //# sourceMappingURL=catchup.js.map