Skip to content

Commit ed32998

Browse files
committed
try reduce size of dump document
1 parent dfe72b5 commit ed32998

1 file changed

Lines changed: 81 additions & 3 deletions

File tree

src/jobs/dump/structures.js

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,85 @@ import currentLocalisationQuery from "../../api/commons/queries/current-localisa
88
import currentNameQuery from "../../api/commons/queries/current-name.query";
99
import currentWebsitesQuery from "../../api/commons/queries/current-websites.query";
1010
import currentSocialsQuery from "../../api/commons/queries/current-socials.query";
11-
import relationsQuery from "../../api/commons/queries/relations.query";
11+
import { relatedObjectLookup, resourceLookup } from './related-object.query';
12+
import relationTypesLightQuery from './relation-types.light.query';
13+
14+
const relationRelatedQuery = [
15+
...relatedObjectLookup,
16+
{
17+
$lookup: {
18+
from: 'relationtypes',
19+
localField: 'relationTypeId',
20+
foreignField: 'id',
21+
pipeline: relationTypesLightQuery,
22+
as: 'relationType',
23+
},
24+
},
25+
{ $set: { relationType: { $arrayElemAt: ['$relationType', 0] } } },
26+
{
27+
$project: {
28+
_id: 0,
29+
id: 1,
30+
structureId: "$resourceId",
31+
relationsGroupId: { $ifNull: ['$relationsGroupId', null] },
32+
relatedObject: 1,
33+
relatedObjectId: 1,
34+
relationType: { $ifNull: ['$relationType', { priority: 99 }] },
35+
relationTag: { $ifNull: ['$relationTag', null] },
36+
startDate: { $ifNull: ['$startDate', null] },
37+
endDate: { $ifNull: ['$endDate', null] },
38+
endDatePrevisional: { $ifNull: ['$endDatePrevisional', null] },
39+
mandatePosition: { $ifNull: ['$mandatePosition', null] },
40+
mandateReason: { $ifNull: ['$mandateReason', null] },
41+
mandateEmail: { $ifNull: ['$mandateEmail', null] },
42+
personalEmail: { $ifNull: ['$personalEmail', null] },
43+
mandatePhonenumber: { $ifNull: ['$mandatePhonenumber', null] },
44+
mandateTemporary: { $ifNull: ['$mandateTemporary', null] },
45+
mandatePrecision: { $ifNull: ['$mandatePrecision', null] },
46+
laureatePrecision: { $ifNull: ['$laureatePrecision', null] },
47+
active: { $ifNull: ['$active', null] },
48+
},
49+
},
50+
];
51+
52+
const relationResourceQuery = [
53+
...resourceLookup,
54+
{
55+
$lookup: {
56+
from: 'relationtypes',
57+
localField: 'relationTypeId',
58+
foreignField: 'id',
59+
pipeline: relationTypesLightQuery,
60+
as: 'relationType',
61+
},
62+
},
63+
{ $set: { relationType: { $arrayElemAt: ['$relationType', 0] } } },
64+
{
65+
$project: {
66+
_id: 0,
67+
id: 1,
68+
structureId: "$relatedObjectId",
69+
relationsGroupId: { $ifNull: ['$relationsGroupId', null] },
70+
relatedObject: "$resource",
71+
relatedObjectId: "$resourceId",
72+
relationType: { $ifNull: ['$relationType', { priority: 99 }] },
73+
relationTag: { $ifNull: ['$relationTag', null] },
74+
startDate: { $ifNull: ['$startDate', null] },
75+
endDate: { $ifNull: ['$endDate', null] },
76+
endDatePrevisional: { $ifNull: ['$endDatePrevisional', null] },
77+
mandatePosition: { $ifNull: ['$mandatePosition', null] },
78+
mandateReason: { $ifNull: ['$mandateReason', null] },
79+
mandateEmail: { $ifNull: ['$mandateEmail', null] },
80+
personalEmail: { $ifNull: ['$personalEmail', null] },
81+
mandatePhonenumber: { $ifNull: ['$mandatePhonenumber', null] },
82+
mandateTemporary: { $ifNull: ['$mandateTemporary', null] },
83+
mandatePrecision: { $ifNull: ['$mandatePrecision', null] },
84+
laureatePrecision: { $ifNull: ['$laureatePrecision', null] },
85+
active: { $ifNull: ['$active', null] },
86+
},
87+
},
88+
];
89+
1290

1391

1492
const structureDumpQuery = [
@@ -25,7 +103,7 @@ const structureDumpQuery = [
25103
from: 'relationships',
26104
localField: 'id',
27105
foreignField: 'resourceId',
28-
pipeline: [...relationsQuery],
106+
pipeline: [...relationRelatedQuery],
29107
as: 'rel1'
30108
}
31109
},
@@ -34,7 +112,7 @@ const structureDumpQuery = [
34112
from: 'relationships',
35113
localField: 'id',
36114
foreignField: 'relatedObjectId',
37-
pipeline: [...relationsQuery],
115+
pipeline: [...relationResourceQuery],
38116
as: 'rel2'
39117
}
40118
},

0 commit comments

Comments
 (0)