@creator-notes/cnotes 0.125.4 → 0.125.5
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/.claude-plugin/plugin.json +1 -1
- package/dist/local-db/sync.js +23 -7
- package/package.json +1 -1
package/dist/local-db/sync.js
CHANGED
|
@@ -30,6 +30,7 @@ export const IDLE_STATUS = {
|
|
|
30
30
|
persistent: false,
|
|
31
31
|
counts: { notes: 0, canvases: 0, placements: 0, answers: 0, bytes: 0 },
|
|
32
32
|
copied: 0,
|
|
33
|
+
step: null,
|
|
33
34
|
syncedAt: null,
|
|
34
35
|
lastPassMs: null,
|
|
35
36
|
firstPassMs: null,
|
|
@@ -48,11 +49,13 @@ const FETCH_CHUNK = 200;
|
|
|
48
49
|
/**
|
|
49
50
|
* Canvases per `placements` call. A canvas can hold thousands of cards, list
|
|
50
51
|
* nodes and list items, and one Convex query reads at most 16,384 documents,
|
|
51
|
-
* so a small batch keeps a workspace of large canvases syncable.
|
|
52
|
+
* so a small batch keeps a workspace of large canvases syncable. No bigger
|
|
53
|
+
* than `MAX_CANVASES_PER_PLACEMENT_CALL` in convex/localDb.ts: the server
|
|
54
|
+
* answers only that many, and boards past it are skipped for the whole pass.
|
|
52
55
|
*/
|
|
53
|
-
const PLACEMENT_CHUNK =
|
|
56
|
+
const PLACEMENT_CHUNK = 3;
|
|
54
57
|
const ANSWER_PAGE = 500;
|
|
55
|
-
/** Parallel
|
|
58
|
+
/** Parallel reads from the server while copying notes and board layouts. */
|
|
56
59
|
const FETCH_PARALLEL = 4;
|
|
57
60
|
const now = () => (typeof performance !== "undefined" ? performance.now() : Date.now());
|
|
58
61
|
const chunks = (items, size) => {
|
|
@@ -149,18 +152,20 @@ export class WorkspaceSync {
|
|
|
149
152
|
try {
|
|
150
153
|
if (!this.opened)
|
|
151
154
|
await this.open(head);
|
|
152
|
-
this.emit({ phase: "syncing", copied: 0 });
|
|
155
|
+
this.emit({ phase: "syncing", copied: 0, step: null });
|
|
153
156
|
const full = !this.reconciled;
|
|
154
157
|
const { canvasesToRefresh, dimensionsToRefresh } = await this.call("applyHead", head);
|
|
155
158
|
const changedTypes = full ? await this.reconcile() : await this.pullChanged(head);
|
|
156
159
|
this.reconciled = true;
|
|
157
160
|
await this.pullPlacements(canvasesToRefresh);
|
|
161
|
+
this.emit({ step: { name: "answers", done: 0, total: null } });
|
|
158
162
|
await this.pullAnswers(head, full ? null : changedTypes, dimensionsToRefresh);
|
|
159
163
|
await this.call("setNewest", this.newest);
|
|
160
164
|
const counts = await this.call("counts", null);
|
|
161
165
|
const ms = now() - start;
|
|
162
166
|
this.emit({
|
|
163
167
|
phase: "ready",
|
|
168
|
+
step: null,
|
|
164
169
|
counts,
|
|
165
170
|
syncedAt: Date.now(),
|
|
166
171
|
lastPassMs: ms,
|
|
@@ -193,6 +198,7 @@ export class WorkspaceSync {
|
|
|
193
198
|
for (;;) {
|
|
194
199
|
const page = await this.source.noteIds(cursor, ID_PAGE);
|
|
195
200
|
ids.push(...page.page);
|
|
201
|
+
this.emit({ step: { name: "listing", done: ids.length, total: null } });
|
|
196
202
|
if (page.isDone)
|
|
197
203
|
break;
|
|
198
204
|
cursor = page.continueCursor;
|
|
@@ -202,12 +208,16 @@ export class WorkspaceSync {
|
|
|
202
208
|
const { toFetch } = await this.call("reconcile", ids);
|
|
203
209
|
await this.call("markReconciled", Date.now());
|
|
204
210
|
const types = new Set();
|
|
211
|
+
let done = 0;
|
|
212
|
+
this.emit({ step: { name: "notes", done, total: toFetch.length } });
|
|
205
213
|
const batches = chunks(toFetch, FETCH_CHUNK);
|
|
206
214
|
for (const group of chunks(batches, FETCH_PARALLEL)) {
|
|
207
215
|
const results = await Promise.all(group.map((batch) => this.source.notesByIds(batch)));
|
|
208
216
|
for (const rows of results) {
|
|
209
217
|
this.track(rows, types);
|
|
210
218
|
await this.call("applyNotes", rows);
|
|
219
|
+
done += rows.length;
|
|
220
|
+
this.emit({ step: { name: "notes", done, total: toFetch.length } });
|
|
211
221
|
}
|
|
212
222
|
}
|
|
213
223
|
return types;
|
|
@@ -235,9 +245,15 @@ export class WorkspaceSync {
|
|
|
235
245
|
return types;
|
|
236
246
|
}
|
|
237
247
|
async pullPlacements(canvasIds) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
248
|
+
let done = 0;
|
|
249
|
+
this.emit({ step: { name: "boards", done, total: canvasIds.length } });
|
|
250
|
+
for (const group of chunks(chunks(canvasIds, PLACEMENT_CHUNK), FETCH_PARALLEL)) {
|
|
251
|
+
const results = await Promise.all(group.map((batch) => this.source.placements(batch)));
|
|
252
|
+
for (const rows of results) {
|
|
253
|
+
await this.call("applyPlacements", rows);
|
|
254
|
+
done += rows.length;
|
|
255
|
+
this.emit({ step: { name: "boards", done, total: canvasIds.length } });
|
|
256
|
+
}
|
|
241
257
|
}
|
|
242
258
|
}
|
|
243
259
|
/**
|