@tmlmobilidade/controllers 20260514.1444.18 → 20260515.1056.47

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.
@@ -15,36 +15,32 @@ export async function getOperationalLinesBatch(query) {
15
15
  start_time_scheduled: { $gte: query.date_start, $lte: query.date_end },
16
16
  },
17
17
  },
18
- {
19
- $sort: {
20
- start_time_scheduled: -1, // newest first
21
- },
22
- },
23
18
  {
24
19
  $group: {
25
20
  _id: '$hashed_trip_id',
26
- agency_id: { $first: '$agency_id' },
27
- hashed_trip_id: { $first: '$hashed_trip_id' },
28
- line_id: { $first: '$line_id' },
29
- operational_date: { $first: '$operational_date' },
30
- plan_id: { $first: '$plan_id' },
31
- start_time_scheduled: { $first: '$start_time_scheduled' },
21
+ latest_ride: {
22
+ $top: {
23
+ output: {
24
+ agency_id: '$agency_id',
25
+ hashed_trip_id: '$hashed_trip_id',
26
+ operational_date: '$operational_date',
27
+ plan_id: '$plan_id',
28
+ start_time_scheduled: '$start_time_scheduled',
29
+ },
30
+ // deterministic tie-break if same timestamp appears multiple times
31
+ sortBy: { start_time_scheduled: -1, _id: -1 },
32
+ },
33
+ },
32
34
  },
33
35
  },
34
36
  {
35
- $sort: {
36
- start_time_scheduled: -1,
37
+ $replaceRoot: {
38
+ newRoot: '$latest_ride',
37
39
  },
38
40
  },
39
41
  {
40
- $project: {
41
- _id: 0,
42
- agency_id: 1,
43
- hashed_trip_id: 1,
44
- line_id: 1,
45
- operational_date: 1,
46
- plan_id: 1,
47
- start_time_scheduled: 1,
42
+ $sort: {
43
+ start_time_scheduled: -1,
48
44
  },
49
45
  },
50
46
  {
@@ -61,11 +57,6 @@ export async function getOperationalLinesBatch(query) {
61
57
  preserveNullAndEmptyArrays: true,
62
58
  },
63
59
  },
64
- {
65
- $sort: {
66
- start_time_scheduled: -1,
67
- },
68
- },
69
60
  {
70
61
  $project: {
71
62
  _id: 0,
@@ -73,12 +64,13 @@ export async function getOperationalLinesBatch(query) {
73
64
  hashed_trip_doc: 1, // full joined document
74
65
  operational_date: 1,
75
66
  plan_id: 1,
67
+ start_time_scheduled: 1,
76
68
  },
77
69
  },
78
70
  ];
79
71
  const ridesCollection = await rides.getCollection();
80
72
  const pipelineResult = await ridesCollection
81
- .aggregate(pipeline)
73
+ .aggregate(pipeline, { allowDiskUse: true })
82
74
  .toArray();
83
75
  Logger.info(`OperationalLinesController.getBatch - pipeline result count: ${pipelineResult?.length ?? 0}`);
84
76
  //
@@ -15,36 +15,32 @@ export async function getOperationalStopsBatch(query) {
15
15
  start_time_scheduled: { $gte: query.date_start, $lte: query.date_end },
16
16
  },
17
17
  },
18
- {
19
- $sort: {
20
- start_time_scheduled: -1, // newest first
21
- },
22
- },
23
18
  {
24
19
  $group: {
25
20
  _id: '$hashed_trip_id',
26
- agency_id: { $first: '$agency_id' },
27
- hashed_trip_id: { $first: '$hashed_trip_id' },
28
- line_id: { $first: '$line_id' },
29
- operational_date: { $first: '$operational_date' },
30
- plan_id: { $first: '$plan_id' },
31
- start_time_scheduled: { $first: '$start_time_scheduled' },
21
+ latest_ride: {
22
+ $top: {
23
+ output: {
24
+ agency_id: '$agency_id',
25
+ hashed_trip_id: '$hashed_trip_id',
26
+ operational_date: '$operational_date',
27
+ plan_id: '$plan_id',
28
+ start_time_scheduled: '$start_time_scheduled',
29
+ },
30
+ // deterministic tie-break if same timestamp appears multiple times
31
+ sortBy: { start_time_scheduled: -1, _id: -1 },
32
+ },
33
+ },
32
34
  },
33
35
  },
34
36
  {
35
- $sort: {
36
- start_time_scheduled: -1,
37
+ $replaceRoot: {
38
+ newRoot: '$latest_ride',
37
39
  },
38
40
  },
39
41
  {
40
- $project: {
41
- _id: 0,
42
- agency_id: 1,
43
- hashed_trip_id: 1,
44
- line_id: 1,
45
- operational_date: 1,
46
- plan_id: 1,
47
- start_time_scheduled: 1,
42
+ $sort: {
43
+ start_time_scheduled: -1,
48
44
  },
49
45
  },
50
46
  {
@@ -61,11 +57,6 @@ export async function getOperationalStopsBatch(query) {
61
57
  preserveNullAndEmptyArrays: true,
62
58
  },
63
59
  },
64
- {
65
- $sort: {
66
- start_time_scheduled: -1,
67
- },
68
- },
69
60
  {
70
61
  $project: {
71
62
  _id: 0,
@@ -73,12 +64,13 @@ export async function getOperationalStopsBatch(query) {
73
64
  hashed_trip_doc: 1, // full joined document
74
65
  operational_date: 1,
75
66
  plan_id: 1,
67
+ start_time_scheduled: 1,
76
68
  },
77
69
  },
78
70
  ];
79
71
  const ridesCollection = await rides.getCollection();
80
72
  const pipelineResult = await ridesCollection
81
- .aggregate(pipeline)
73
+ .aggregate(pipeline, { allowDiskUse: true })
82
74
  .toArray();
83
75
  Logger.info(`OperationalStopsController.getBatch - pipeline result count: ${pipelineResult?.length ?? 0}`);
84
76
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/controllers",
3
- "version": "20260514.1444.18",
3
+ "version": "20260515.1056.47",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"