@hatk/hatk 0.0.1-alpha.6 → 0.0.1-alpha.8

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.
@@ -1 +1 @@
1
- {"version":3,"file":"backfill.d.ts","sourceRoot":"","sources":["../src/backfill.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,6CAA6C;AAC7C,UAAU,YAAY;IACpB,wFAAwF;IACxF,MAAM,EAAE,MAAM,CAAA;IACd,8FAA8F;IAC9F,MAAM,EAAE,MAAM,CAAA;IACd,yEAAyE;IACzE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACxB,qDAAqD;IACrD,MAAM,EAAE,cAAc,CAAA;CACvB;AAuGD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmH/G;AAgCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAiInE"}
1
+ {"version":3,"file":"backfill.d.ts","sourceRoot":"","sources":["../src/backfill.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,6CAA6C;AAC7C,UAAU,YAAY;IACpB,wFAAwF;IACxF,MAAM,EAAE,MAAM,CAAA;IACd,8FAA8F;IAC9F,MAAM,EAAE,MAAM,CAAA;IACd,yEAAyE;IACzE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACxB,qDAAqD;IACrD,MAAM,EAAE,cAAc,CAAA;CACvB;AAuGD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2H/G;AAgCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAiInE"}
package/dist/backfill.js CHANGED
@@ -156,7 +156,24 @@ export async function backfillRepo(did, collections, fetchTimeout) {
156
156
  const { value: commit } = cborDecode(rootData);
157
157
  // Walk MST to find all record paths
158
158
  const entries = walkMst(blocks, commit.data.$link);
159
- const bulk = [];
159
+ // Delete existing records for this DID before re-importing so deletions are reflected
160
+ for (const col of collections) {
161
+ const schema = getSchema(col);
162
+ if (!schema)
163
+ continue;
164
+ await runSQL(`DELETE FROM ${schema.tableName} WHERE did = $1`, did);
165
+ for (const child of schema.children) {
166
+ await runSQL(`DELETE FROM ${child.tableName} WHERE parent_did = $1`, did);
167
+ }
168
+ for (const union of schema.unions) {
169
+ for (const branch of union.branches) {
170
+ await runSQL(`DELETE FROM ${branch.tableName} WHERE parent_did = $1`, did);
171
+ }
172
+ }
173
+ }
174
+ // Insert records in chunks to limit memory usage
175
+ const CHUNK_SIZE = 1000;
176
+ let chunk = [];
160
177
  for (const entry of entries) {
161
178
  const collection = entry.path.split('/')[0];
162
179
  if (!collections.has(collection))
@@ -170,7 +187,11 @@ export async function backfillRepo(did, collections, fetchTimeout) {
170
187
  continue;
171
188
  const rkey = entry.path.split('/').slice(1).join('/');
172
189
  const uri = `at://${did}/${collection}/${rkey}`;
173
- bulk.push({ collection, uri, cid: entry.cid, did, record });
190
+ chunk.push({ collection, uri, cid: entry.cid, did, record });
191
+ if (chunk.length >= CHUNK_SIZE) {
192
+ count += await bulkInsertRecords(chunk);
193
+ chunk = [];
194
+ }
174
195
  }
175
196
  catch (recordErr) {
176
197
  emit('backfill', 'record_error', {
@@ -181,23 +202,10 @@ export async function backfillRepo(did, collections, fetchTimeout) {
181
202
  });
182
203
  }
183
204
  }
184
- blocks = null; // free block map before bulk insert
185
- // Delete existing records for this DID before re-importing so deletions are reflected
186
- for (const col of collections) {
187
- const schema = getSchema(col);
188
- if (!schema)
189
- continue;
190
- await runSQL(`DELETE FROM ${schema.tableName} WHERE did = $1`, did);
191
- for (const child of schema.children) {
192
- await runSQL(`DELETE FROM ${child.tableName} WHERE parent_did = $1`, did);
193
- }
194
- for (const union of schema.unions) {
195
- for (const branch of union.branches) {
196
- await runSQL(`DELETE FROM ${branch.tableName} WHERE parent_did = $1`, did);
197
- }
198
- }
205
+ blocks = null; // free block map
206
+ if (chunk.length > 0) {
207
+ count += await bulkInsertRecords(chunk);
199
208
  }
200
- count = await bulkInsertRecords(bulk);
201
209
  await setRepoStatus(did, 'active', commit.rev, { handle });
202
210
  return count;
203
211
  }
package/dist/cli.js CHANGED
@@ -848,7 +848,7 @@ COPY . .
848
848
  RUN node_modules/.bin/hatk build
849
849
  RUN npm prune --omit=dev
850
850
  EXPOSE 3000
851
- CMD ["node", "--max-old-space-size=256", "node_modules/@hatk/hatk/dist/main.js", "config.yaml"]
851
+ CMD ["node", "--max-old-space-size=512", "node_modules/@hatk/hatk/dist/main.js", "config.yaml"]
852
852
  `);
853
853
  const pkgDeps = { '@hatk/oauth-client': '*', hatk: '*' };
854
854
  const pkgDevDeps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatk/hatk",
3
- "version": "0.0.1-alpha.6",
3
+ "version": "0.0.1-alpha.8",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "hatk": "dist/cli.js"