@dhyasama/totem-models 12.14.0 → 12.15.0

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.
Files changed (2) hide show
  1. package/lib/Deal.js +15 -66
  2. package/package.json +2 -2
package/lib/Deal.js CHANGED
@@ -331,27 +331,19 @@ module.exports = function(mongoose, config) {
331
331
  // },
332
332
 
333
333
  // get the referrer
334
+ // NOTE: use localField/foreignField (not sub-pipeline + $expr). The
335
+ // sub-pipeline form does not use the foreign collection's _id index
336
+ // and is ~100x slower in practice — for customers with hundreds of
337
+ // deals, the difference between the two forms is the difference
338
+ // between a sub-second response and a 120-second timeout. Verified on
339
+ // production data 2026-04-07: Saltwater (20 deals) 32.5s -> 61ms,
340
+ // Gobi Partners (1845 deals) timed out -> 920ms.
334
341
  {
335
342
  $lookup:
336
343
  {
337
344
  from: "people",
338
- let: { referrerPersonId: "$referrer.person" },
339
- pipeline: [
340
- {
341
- $match: {
342
- $expr: {
343
- $eq: ["$_id", "$$referrerPersonId"]
344
- }
345
- }
346
- },
347
- {
348
- $project: {
349
- name: 1,
350
- avatarUrl: 1,
351
- title: 1
352
- }
353
- }
354
- ],
345
+ localField: "referrer.person",
346
+ foreignField: "_id",
355
347
  as: "referrerPerson"
356
348
  }
357
349
  },
@@ -361,27 +353,8 @@ module.exports = function(mongoose, config) {
361
353
  $lookup:
362
354
  {
363
355
  from: "documents",
364
- let: { docIds: { $ifNull: ["$documents", []] } },
365
- pipeline: [
366
- {
367
- $match: {
368
- $expr: {
369
- $in: ["$_id", "$$docIds"]
370
- }
371
- }
372
- },
373
- {
374
- $project: {
375
- name: 1,
376
- type: 1,
377
- contentType: 1,
378
- s3: 1,
379
- createdOn: 1,
380
- createdBy: 1,
381
- customer: 1
382
- }
383
- }
384
- ],
356
+ localField: "documents",
357
+ foreignField: "_id",
385
358
  as: "documents"
386
359
  }
387
360
  },
@@ -391,16 +364,8 @@ module.exports = function(mongoose, config) {
391
364
  $lookup:
392
365
  {
393
366
  from: "messages",
394
- let: { messageIds: { $ifNull: ["$messages", []] } },
395
- pipeline: [
396
- {
397
- $match: {
398
- $expr: {
399
- $in: ["$_id", "$$messageIds"]
400
- }
401
- }
402
- }
403
- ],
367
+ localField: "messages",
368
+ foreignField: "_id",
404
369
  as: "messages"
405
370
  }
406
371
  },
@@ -410,24 +375,8 @@ module.exports = function(mongoose, config) {
410
375
  $lookup:
411
376
  {
412
377
  from: "messages",
413
- let: { latestMessageId: "$latestMessage" },
414
- pipeline: [
415
- {
416
- $match: {
417
- $expr: {
418
- $eq: ["$_id", "$$latestMessageId"]
419
- }
420
- }
421
- },
422
- {
423
- $project: {
424
- subject: 1,
425
- originalMessageDate: 1,
426
- createdOn: 1,
427
- messageDate: 1
428
- }
429
- }
430
- ],
378
+ localField: "latestMessage",
379
+ foreignField: "_id",
431
380
  as: "latestMessage"
432
381
  }
433
382
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "12.14.0",
3
+ "version": "12.15.0",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",
7
7
  "main": "index.js",
8
8
  "engines": {
9
- "node": ">=18.0.0"
9
+ "node": ">=24 <25"
10
10
  },
11
11
  "scripts": {
12
12
  "smoke:mongoose8": "node scripts/run_mongoose8_smoke.js",