From cfef5a26f324d02fd9fee6277ab27a6fb0e53013 Mon Sep 17 00:00:00 2001 From: maciejpedzich Date: Tue, 5 Jul 2022 09:28:17 +0200 Subject: [PATCH] Add note about picking items with the same keys --- server/api/playlists/[playlistId]/snapshots.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/api/playlists/[playlistId]/snapshots.ts b/server/api/playlists/[playlistId]/snapshots.ts index 1f79a1d..8d1b0c7 100644 --- a/server/api/playlists/[playlistId]/snapshots.ts +++ b/server/api/playlists/[playlistId]/snapshots.ts @@ -5,9 +5,13 @@ import { filterByUniqueKeyValue } from '~~/server/utils/filterByUniqueKeyValue'; export default defineEventHandler(async (event) => { const query = useQuery(event); - const sinceDateParam = (query.sinceDate as unknown as string) || '2021-12-01'; + + const sinceDateParam = + (query.sinceDate as unknown as string) || '2021-12-01T00:00:00.000Z'; + const untilDateParam = (query.untilDate as unknown as string) || new Date().toISOString(); + const DECEMBER_1ST_2021_TIMESTAMP = 16383168e5; const since = new Date( @@ -43,6 +47,10 @@ export default defineEventHandler(async (event) => { dateCaptured: commitListings[index].commit.author.date }) ); + + // Since the above's entries are sorted by the latest dateCaptured first, + // the following will preserve the last item with a duplicate key value. + // Therefore, we'll be left with entries containing the earliest dateCaptured... const uniqueSnapshotEntries = filterByUniqueKeyValue( possiblyDuplicateSnapshotEntries, 'snapshotId'