@dhyasama/totem-models 12.14.0 → 12.15.1
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/lib/Deal.js +15 -66
- package/lib/Round.js +8 -12
- 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
|
-
|
|
339
|
-
|
|
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
|
-
|
|
365
|
-
|
|
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
|
-
|
|
395
|
-
|
|
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
|
-
|
|
414
|
-
|
|
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/lib/Round.js
CHANGED
|
@@ -806,19 +806,15 @@ module.exports = function(mongoose, config) {
|
|
|
806
806
|
if (!options) { throw new Error('options is required'); }
|
|
807
807
|
if (!options.CUSTOMER_ID) { throw new Error('options.CUSTOMER_ID is required'); }
|
|
808
808
|
if (!mongoose.Types.ObjectId.isValid(options.CUSTOMER_ID)) { throw new Error('options.CUSTOMER_ID is not a valid ObjectId'); }
|
|
809
|
-
|
|
810
|
-
|
|
809
|
+
if (!options.customerFunds) { throw new Error('options.customerFunds is required'); }
|
|
810
|
+
|
|
811
|
+
// Fund has no direct customer field — callers are expected to compute
|
|
812
|
+
// customerFunds via the web-app's cacheHelpers.getCustomerFunds and pass
|
|
813
|
+
// it in. A previous fallback tried to call Fund.findByCustomer(), which
|
|
814
|
+
// has never existed on the Fund model; the fallback was unreachable dead
|
|
815
|
+
// code masked by the fact that every production caller already passes
|
|
816
|
+
// customerFunds explicitly.
|
|
811
817
|
var customerFunds = options.customerFunds;
|
|
812
|
-
if (!customerFunds) {
|
|
813
|
-
const Fund = mongoose.model('Fund');
|
|
814
|
-
const funds = await new Promise((resolve, reject) => {
|
|
815
|
-
Fund.findByCustomer(options.CUSTOMER_ID, (err, result) => {
|
|
816
|
-
if (err) reject(err); else resolve(result);
|
|
817
|
-
});
|
|
818
|
-
});
|
|
819
|
-
options.customerFunds = funds;
|
|
820
|
-
customerFunds = funds;
|
|
821
|
-
}
|
|
822
818
|
|
|
823
819
|
// Find organizations acquired by this org (acquirees)
|
|
824
820
|
const acquirees = await Organization
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhyasama/totem-models",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.15.1",
|
|
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": ">=
|
|
9
|
+
"node": ">=24 <25"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"smoke:mongoose8": "node scripts/run_mongoose8_smoke.js",
|