@openinc/parse-server-opendash 4.8.4 → 4.8.6

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,7 +97,7 @@ 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
+ const page = await (0, pass_js_1.stableOrder)(relation.query().limit(batchSize).skip(skip)).find(env_js_1.MK);
104
101
  if (page.length === 0)
105
102
  break;
106
103
  out.push(...page);
@@ -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,20 @@ 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 in the migration uses the same {@link STABLE_ORDER}.
43
49
  */
44
50
  export declare function pages<T extends Parse.Object>(build: () => Parse.Query<T>, batchSize: number): AsyncGenerator<T[]>;
51
+ /** Insert order with a unique tie-breaker — the only safe order to `skip` over. */
52
+ export declare const STABLE_ORDER: readonly ["createdAt", "objectId"];
53
+ /** Apply {@link STABLE_ORDER} to a query that is about to be paged with `skip`. */
54
+ export declare function stableOrder<T extends Parse.Object>(query: Parse.Query<T>): Parse.Query<T>;
45
55
  /**
46
56
  * Count rows by paging, not with `Query.count()`.
47
57
  *
@@ -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,19 @@ 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 in the migration uses the same {@link STABLE_ORDER}.
30
38
  */
31
39
  async function* pages(build, batchSize) {
32
40
  let skip = 0;
33
41
  for (;;) {
34
- const page = await build().limit(batchSize).skip(skip).ascending("createdAt").find(env_js_1.MK);
42
+ const page = await stableOrder(build().limit(batchSize).skip(skip)).find(env_js_1.MK);
35
43
  if (page.length === 0)
36
44
  return;
37
45
  yield page;
@@ -39,6 +47,12 @@ async function* pages(build, batchSize) {
39
47
  skip += page.length;
40
48
  }
41
49
  }
50
+ /** Insert order with a unique tie-breaker — the only safe order to `skip` over. */
51
+ exports.STABLE_ORDER = ["createdAt", "objectId"];
52
+ /** Apply {@link STABLE_ORDER} to a query that is about to be paged with `skip`. */
53
+ function stableOrder(query) {
54
+ return query.ascending(...exports.STABLE_ORDER);
55
+ }
42
56
  /**
43
57
  * Count rows by paging, not with `Query.count()`.
44
58
  *
@@ -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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.8.4",
3
+ "version": "4.8.6",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@11.25.0",
6
6
  "keywords": [