@secondlayer/subgraphs 1.3.1 → 1.3.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.
@@ -187,9 +187,9 @@ class SubgraphContext {
187
187
  const blockHeight = op.data._block_height ?? this.block.height;
188
188
  const txId = op.data._tx_id ?? this._tx.txId;
189
189
  const baseRow = op.kind === "update" ? { ...op.data, ...op.set ?? {} } : { ...op.data };
190
- delete baseRow._upsert_keys;
191
- delete baseRow._upsert_fallback_keys;
192
- delete baseRow._upsert_fallback_set;
190
+ baseRow._upsert_keys = undefined;
191
+ baseRow._upsert_fallback_keys = undefined;
192
+ baseRow._upsert_fallback_set = undefined;
193
193
  return {
194
194
  op: op.kind,
195
195
  table: op.table,
@@ -1336,16 +1336,16 @@ function generateSubgraphSQL(def, schemaNameOverride) {
1336
1336
  const statements = [];
1337
1337
  const needsTrgm = Object.values(def.schema).some((table) => Object.values(table.columns).some((col) => col.search));
1338
1338
  if (needsTrgm) {
1339
- statements.push(`CREATE EXTENSION IF NOT EXISTS pg_trgm`);
1339
+ statements.push("CREATE EXTENSION IF NOT EXISTS pg_trgm");
1340
1340
  }
1341
1341
  statements.push(`CREATE SCHEMA IF NOT EXISTS ${schemaName}`);
1342
1342
  for (const [tableName, tableDef] of Object.entries(def.schema)) {
1343
1343
  const qualifiedName = `${schemaName}.${tableName}`;
1344
1344
  const columnDefs = [
1345
- `_id BIGSERIAL PRIMARY KEY`,
1346
- `_block_height BIGINT NOT NULL`,
1347
- `_tx_id TEXT NOT NULL`,
1348
- `_created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()`
1345
+ "_id BIGSERIAL PRIMARY KEY",
1346
+ "_block_height BIGINT NOT NULL",
1347
+ "_tx_id TEXT NOT NULL",
1348
+ "_created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()"
1349
1349
  ];
1350
1350
  for (const [colName, col] of Object.entries(tableDef.columns)) {
1351
1351
  const sqlType = TYPE_MAP[col.type];
@@ -1441,6 +1441,7 @@ function avgEventsPerBlock(batch) {
1441
1441
  // src/runtime/reindex.ts
1442
1442
  var LOG_INTERVAL = 1000;
1443
1443
  var HEALTH_FLUSH_INTERVAL = 1000;
1444
+ var PROGRESS_FLUSH_INTERVAL_MS = 5000;
1444
1445
  var HOBBY_REINDEX_BATCH_CONFIG = {
1445
1446
  defaultBatchSize: 50,
1446
1447
  minBatchSize: 25,
@@ -1515,6 +1516,8 @@ async function processBlockRange(def, opts) {
1515
1516
  let pendingErrors = 0;
1516
1517
  let pendingLastError;
1517
1518
  let lastHealthFlushBlock = 0;
1519
+ let lastHealthFlushAt = Date.now();
1520
+ let lastProgressFlushAt = Date.now();
1518
1521
  const batchConfig = resolveReindexBatchConfig();
1519
1522
  let batchSize = batchConfig.defaultBatchSize;
1520
1523
  let currentHeight = fromBlock;
@@ -1527,6 +1530,7 @@ async function processBlockRange(def, opts) {
1527
1530
  pendingErrors = 0;
1528
1531
  pendingLastError = undefined;
1529
1532
  lastHealthFlushBlock = blocksProcessed;
1533
+ lastHealthFlushAt = Date.now();
1530
1534
  };
1531
1535
  let nextBatchEnd = Math.min(currentHeight + batchSize - 1, toBlock);
1532
1536
  let nextBatchPromise = loadBlockRange(sourceDb, currentHeight, nextBatchEnd);
@@ -1590,8 +1594,11 @@ async function processBlockRange(def, opts) {
1590
1594
  await stats.flush(targetDb);
1591
1595
  }
1592
1596
  }
1593
- if (blocksProcessed % 100 === 0) {
1597
+ const now = Date.now();
1598
+ const shouldFlushProgress = blocksProcessed % 100 === 0 || now - lastProgressFlushAt >= PROGRESS_FLUSH_INTERVAL_MS;
1599
+ if (shouldFlushProgress) {
1594
1600
  await updateSubgraphStatus2(targetDb, subgraphName, status, height);
1601
+ lastProgressFlushAt = now;
1595
1602
  }
1596
1603
  if (blocksProcessed % LOG_INTERVAL === 0) {
1597
1604
  logger5.info(`${status === "reindexing" ? "Reindex" : "Backfill"} progress`, {
@@ -1603,7 +1610,11 @@ async function processBlockRange(def, opts) {
1603
1610
  });
1604
1611
  }
1605
1612
  }
1606
- if (blocksProcessed - lastHealthFlushBlock >= HEALTH_FLUSH_INTERVAL) {
1613
+ if (status === "reindexing" && blocksProcessed > 0) {
1614
+ await updateSubgraphStatus2(targetDb, subgraphName, status, batchEnd);
1615
+ }
1616
+ const shouldFlushHealth = blocksProcessed - lastHealthFlushBlock >= HEALTH_FLUSH_INTERVAL || Date.now() - lastHealthFlushAt >= PROGRESS_FLUSH_INTERVAL_MS;
1617
+ if (shouldFlushHealth) {
1607
1618
  await flushHealth();
1608
1619
  }
1609
1620
  if (batchFailedBlocks.length > 0 && opts.subgraphId) {
@@ -1849,5 +1860,5 @@ export {
1849
1860
  backfillSubgraph
1850
1861
  };
1851
1862
 
1852
- //# debugId=B7B10AB9772AECD264756E2164756E21
1863
+ //# debugId=7C79195F11AC7A3264756E2164756E21
1853
1864
  //# sourceMappingURL=reindex.js.map