@tmlmobilidade/go-utils-exec 20260829.1149.32 → 20260829.1307.28
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.
|
@@ -9,7 +9,7 @@ export interface PerformInTimeChunksOptions {
|
|
|
9
9
|
endDate?: UnixMilliseconds;
|
|
10
10
|
intervalHrs: number;
|
|
11
11
|
onChunk: (chunk: PerformInTimeChunksItem) => Promise<void>;
|
|
12
|
-
order
|
|
12
|
+
order: 'asc' | 'desc';
|
|
13
13
|
startDate: UnixMilliseconds;
|
|
14
14
|
}
|
|
15
15
|
export declare function performInTimeChunks({ endDate, intervalHrs, onChunk, order, startDate }: PerformInTimeChunksOptions): Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* * */
|
|
2
2
|
import { Dates, splitTimeIntervals } from '@tmlmobilidade/go-utils-dates';
|
|
3
|
-
export async function performInTimeChunks({ endDate, intervalHrs, onChunk, order
|
|
3
|
+
export async function performInTimeChunks({ endDate, intervalHrs, onChunk, order, startDate }) {
|
|
4
4
|
//
|
|
5
5
|
// In order to sync both collections in a manageable way, due to the high volume of data,
|
|
6
6
|
// it is necessary to divide the process into smaller blocks. Instead of syncing all documents at once,
|
|
@@ -9,13 +9,7 @@ export async function performInTimeChunks({ endDate, intervalHrs, onChunk, order
|
|
|
9
9
|
// More recent data is more important than older data, so we start syncing the most recent data first.
|
|
10
10
|
// It makes sense to divide chunks by day, but this should be adjusted according to the volume of data in each chunk.
|
|
11
11
|
const endDateValue = endDate || Dates.now('utc').minus({ seconds: 30 }).unix_milliseconds;
|
|
12
|
-
const allTimestampChunks = splitTimeIntervals(startDate, endDateValue, intervalHrs);
|
|
13
|
-
//
|
|
14
|
-
// Sort the timestamp chunks in the desired order.
|
|
15
|
-
// Timestamp chunks are usually sorted in descending order, so that more recent data is processed first.
|
|
16
|
-
// Timestamp chunks are in the format { start: day1, end: day2 }, so end is always greater than start.
|
|
17
|
-
// This might be confusing as the array of chunks itself is sorted in descending order, but the chunks individually are not.
|
|
18
|
-
allTimestampChunks.sort((a, b) => order === 'asc' ? a.start - b.start : b.start - a.start);
|
|
12
|
+
const allTimestampChunks = splitTimeIntervals(startDate, endDateValue, intervalHrs, order);
|
|
19
13
|
//
|
|
20
14
|
// Iterate over each timestamp chunk and sync the documents.
|
|
21
15
|
// Timestamp chunks are sorted in descending order, so that more recent data is processed first.
|