@dhyasama/totem-models 12.13.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.
- package/lib/Deal.js +15 -66
- package/lib/DiffbotArticle.js +9 -7
- package/lib/DiffbotOrganization.js +9 -7
- package/lib/News.js +8 -5
- 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/DiffbotArticle.js
CHANGED
|
@@ -60,13 +60,15 @@ module.exports = function(mongoose, config) {
|
|
|
60
60
|
DiffbotArticle.statics.upsert = function (doc, cb) {
|
|
61
61
|
|
|
62
62
|
const run = async () => {
|
|
63
|
-
doc.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
const update = doc.toObject ? doc.toObject() : doc;
|
|
64
|
+
delete update._id;
|
|
65
|
+
delete update.__v;
|
|
66
|
+
update.updatedOn = new Date();
|
|
67
|
+
return await this.findOneAndUpdate(
|
|
68
|
+
{ entityId: update.entityId },
|
|
69
|
+
update,
|
|
70
|
+
{ upsert: true, new: true }
|
|
71
|
+
);
|
|
70
72
|
};
|
|
71
73
|
|
|
72
74
|
if (typeof cb === 'function') { run().then(result => cb(null, result), err => cb(err)); return; }
|
|
@@ -59,13 +59,15 @@ module.exports = function(mongoose, config) {
|
|
|
59
59
|
DiffbotOrganization.statics.upsert = function (doc, cb) {
|
|
60
60
|
|
|
61
61
|
const run = async () => {
|
|
62
|
-
doc.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
const update = doc.toObject ? doc.toObject() : doc;
|
|
63
|
+
delete update._id;
|
|
64
|
+
delete update.__v;
|
|
65
|
+
update.updatedOn = new Date();
|
|
66
|
+
return await this.findOneAndUpdate(
|
|
67
|
+
{ org: update.org },
|
|
68
|
+
update,
|
|
69
|
+
{ upsert: true, new: true }
|
|
70
|
+
);
|
|
69
71
|
};
|
|
70
72
|
|
|
71
73
|
if (typeof cb === 'function') { run().then(result => cb(null, result), err => cb(err)); return; }
|
package/lib/News.js
CHANGED
|
@@ -115,11 +115,14 @@ module.exports = function(mongoose, config) {
|
|
|
115
115
|
News.statics.upsert = function (news, cb) {
|
|
116
116
|
|
|
117
117
|
const run = async () => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
const update = news.toObject ? news.toObject() : news;
|
|
119
|
+
delete update._id;
|
|
120
|
+
delete update.__v;
|
|
121
|
+
return await this.findOneAndUpdate(
|
|
122
|
+
{ diffbotUri: update.diffbotUri },
|
|
123
|
+
update,
|
|
124
|
+
{ upsert: true, new: true }
|
|
125
|
+
);
|
|
123
126
|
};
|
|
124
127
|
|
|
125
128
|
if (typeof cb === 'function') { run().then(result => cb(null, result), err => cb(err)); return; }
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhyasama/totem-models",
|
|
3
|
-
"version": "12.
|
|
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": ">=
|
|
9
|
+
"node": ">=24 <25"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"smoke:mongoose8": "node scripts/run_mongoose8_smoke.js",
|