@openinc/parse-server-opendash 4.8.5 → 4.8.7

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.
@@ -26,14 +26,11 @@ async function groupByTicket(build, batchSize, ticketField = "ticket") {
26
26
  const byTicket = new Map();
27
27
  let skip = 0;
28
28
  for (;;) {
29
- const page = await build()
30
- .limit(batchSize)
31
- .skip(skip)
32
- // Ascending, so each ticket's bucket comes out in chronological order —
33
- // which is exactly what the history replay (pass 12) needs, and the last
34
- // element is what the fold (pass 08) needs.
35
- .ascending("createdAt")
36
- .find(env_js_1.MK);
29
+ // Ascending, so each ticket's bucket comes out in chronological order —
30
+ // which is exactly what the history replay (pass 12) needs, and the last
31
+ // element is what the fold (pass 08) needs. `stableOrder` also breaks
32
+ // `createdAt` ties, without which `skip` repeats and drops rows.
33
+ const page = await (0, pass_js_1.stableOrder)(build().limit(batchSize).skip(skip)).find(env_js_1.MK);
37
34
  if (page.length === 0)
38
35
  break;
39
36
  for (const row of page) {
@@ -100,13 +97,27 @@ async function relationObjects(owner, field, batchSize = 500) {
100
97
  const out = [];
101
98
  let skip = 0;
102
99
  for (;;) {
103
- const page = await relation.query().limit(batchSize).skip(skip).find(env_js_1.MK);
100
+ // Not `stableOrder`: a relation query sorted by `createdAt` makes Parse
101
+ // page the *join table* instead of the objects
102
+ // (`DatabaseController.relatedIds`), while this loop advances by the
103
+ // objects that came back. A join row whose object is gone — v1 deleted
104
+ // steps and media without unlinking them — then shifts every later page
105
+ // and repeats objects: the first customer run wrote a template with one
106
+ // step twice. `objectId` alone is unique and keeps paging on the objects.
107
+ const page = await relation
108
+ .query()
109
+ .limit(batchSize)
110
+ .skip(skip)
111
+ .ascending("objectId")
112
+ .find(env_js_1.MK);
104
113
  if (page.length === 0)
105
114
  break;
106
115
  out.push(...page);
107
116
  skip += page.length;
108
117
  }
109
- return out;
118
+ // Insert order for the callers, restored in memory.
119
+ return out.sort((a, b) => (a.createdAt?.getTime() ?? 0) - (b.createdAt?.getTime() ?? 0) ||
120
+ (a.id ?? "").localeCompare(b.id ?? ""));
110
121
  }
111
122
  /** The objectIds of a relation, read completely. */
112
123
  async function relationIds(owner, field, batchSize = 500) {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.MigrationMap = exports.MIGRATION_MAP_CLASS = void 0;
7
7
  const node_1 = __importDefault(require("parse/node"));
8
8
  const env_js_1 = require("./env.js");
9
+ const pass_js_1 = require("./pass.js");
9
10
  /** Exported so the orchestrator can name it in a connection error. */
10
11
  exports.MIGRATION_MAP_CLASS = "OD3_Service_MigrationMap";
11
12
  const CLASS_NAME = exports.MIGRATION_MAP_CLASS;
@@ -50,11 +51,10 @@ class MigrationMap {
50
51
  return;
51
52
  let skip = 0;
52
53
  for (;;) {
53
- const page = await new node_1.default.Query(CLASS_NAME)
54
- .limit(1000)
55
- .skip(skip)
56
- .ascending("createdAt")
57
- .find(env_js_1.MK);
54
+ // A real run writes map rows in bursts, many in the same millisecond;
55
+ // without the tie-breaker a re-run would miss mappings and duplicate
56
+ // their targets.
57
+ const page = await (0, pass_js_1.stableOrder)(new node_1.default.Query(CLASS_NAME).limit(1000).skip(skip)).find(env_js_1.MK);
58
58
  if (page.length === 0)
59
59
  break;
60
60
  for (const row of page) {
@@ -38,10 +38,21 @@ export interface Pass {
38
38
  * issues roughly ten point queries per ticket, which at 10k tickets is 100k
39
39
  * round-trips. Passes load each source table once in pages and reduce in memory.
40
40
  *
41
- * Ordered by `createdAt` so paging is stable and so passes that depend on insert
42
- * order (tickets, whose numbers come from the backend counter) get it for free.
41
+ * Ordered by `createdAt` so passes that depend on insert order (tickets, whose
42
+ * numbers come from the backend counter) get it for free — **and then by
43
+ * `objectId`**, because `createdAt` alone is not unique. v1 wrote rows in bursts
44
+ * (one afterSave, several messages in the same millisecond), and MongoDB may
45
+ * order ties differently on every query. With `skip` paging that returns a row on
46
+ * two pages and silently drops another — the first customer dry run did exactly
47
+ * that: pass 10 "updated" 4 comments with an empty map, i.e. saw 4 twice and
48
+ * missed 4. Every paging loop over a class uses the same {@link STABLE_ORDER};
49
+ * relation queries must not — see `relationObjects`.
43
50
  */
44
51
  export declare function pages<T extends Parse.Object>(build: () => Parse.Query<T>, batchSize: number): AsyncGenerator<T[]>;
52
+ /** Insert order with a unique tie-breaker — the only safe order to `skip` over. */
53
+ export declare const STABLE_ORDER: readonly ["createdAt", "objectId"];
54
+ /** Apply {@link STABLE_ORDER} to a query that is about to be paged with `skip`. */
55
+ export declare function stableOrder<T extends Parse.Object>(query: Parse.Query<T>): Parse.Query<T>;
45
56
  /**
46
57
  * Count rows by paging, not with `Query.count()`.
47
58
  *
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STABLE_ORDER = void 0;
3
4
  exports.pages = pages;
5
+ exports.stableOrder = stableOrder;
4
6
  exports.countAll = countAll;
5
7
  exports.all = all;
6
8
  exports.scopeToTenant = scopeToTenant;
@@ -25,13 +27,20 @@ const env_js_1 = require("./env.js");
25
27
  * issues roughly ten point queries per ticket, which at 10k tickets is 100k
26
28
  * round-trips. Passes load each source table once in pages and reduce in memory.
27
29
  *
28
- * Ordered by `createdAt` so paging is stable and so passes that depend on insert
29
- * order (tickets, whose numbers come from the backend counter) get it for free.
30
+ * Ordered by `createdAt` so passes that depend on insert order (tickets, whose
31
+ * numbers come from the backend counter) get it for free — **and then by
32
+ * `objectId`**, because `createdAt` alone is not unique. v1 wrote rows in bursts
33
+ * (one afterSave, several messages in the same millisecond), and MongoDB may
34
+ * order ties differently on every query. With `skip` paging that returns a row on
35
+ * two pages and silently drops another — the first customer dry run did exactly
36
+ * that: pass 10 "updated" 4 comments with an empty map, i.e. saw 4 twice and
37
+ * missed 4. Every paging loop over a class uses the same {@link STABLE_ORDER};
38
+ * relation queries must not — see `relationObjects`.
30
39
  */
31
40
  async function* pages(build, batchSize) {
32
41
  let skip = 0;
33
42
  for (;;) {
34
- const page = await build().limit(batchSize).skip(skip).ascending("createdAt").find(env_js_1.MK);
43
+ const page = await stableOrder(build().limit(batchSize).skip(skip)).find(env_js_1.MK);
35
44
  if (page.length === 0)
36
45
  return;
37
46
  yield page;
@@ -39,6 +48,12 @@ async function* pages(build, batchSize) {
39
48
  skip += page.length;
40
49
  }
41
50
  }
51
+ /** Insert order with a unique tie-breaker — the only safe order to `skip` over. */
52
+ exports.STABLE_ORDER = ["createdAt", "objectId"];
53
+ /** Apply {@link STABLE_ORDER} to a query that is about to be paged with `skip`. */
54
+ function stableOrder(query) {
55
+ return query.ascending(...exports.STABLE_ORDER);
56
+ }
42
57
  /**
43
58
  * Count rows by paging, not with `Query.count()`.
44
59
  *
@@ -376,7 +376,8 @@ exports.pass03 = {
376
376
  }
377
377
  if (inheritsTag > 0) {
378
378
  report.info(entry, `${inheritsTag} equipment without a tag of their own sit below a tagged ` +
379
- `parent — the header picker reaches them through it`);
379
+ `ancestor — the header picker shows them only while the selected ` +
380
+ `source is that ancestor's or one above it`);
380
381
  }
381
382
  // Header data last: it needs the equipment ids this loop just handed out.
382
383
  await migrateSourceMeta(ctx, allSources, equipmentBySource);
@@ -218,6 +218,10 @@ exports.pass16 = {
218
218
  updatedAt: row.updatedAt,
219
219
  });
220
220
  configIds.set(context, id);
221
+ // A step met twice in one run must update, not create a second config.
222
+ if (!existing) {
223
+ existingConfigs.set(context, new index_js_1.Meta_Config({ objectId: id }));
224
+ }
221
225
  existing ? entry.updated++ : entry.created++;
222
226
  configsWritten += 1;
223
227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.8.5",
3
+ "version": "4.8.7",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@11.25.0",
6
6
  "keywords": [