mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-11 22:02:21 +00:00
Merge pull request #1666 from bilawalsidhu/sameh/gdelt-tie-order
fix(news): Conflicts reports of the same time come in a fixed order
This commit is contained in:
1 file changed
+8
-1
@@ -642,9 +642,16 @@ export function createKeyedNews({
|
|||||||
await firstAnswer(inFlight.get('gdelt'));
|
await firstAnswer(inFlight.get('gdelt'));
|
||||||
if (!current()) return { failed: true };
|
if (!current()) return { failed: true };
|
||||||
const dayAgo = new Date(now() - DAY_MS).toISOString();
|
const dayAgo = new Date(now() - DAY_MS).toISOString();
|
||||||
|
// Exports are read in parallel, so reports of one time arrive in any
|
||||||
|
// order: the most mentioned comes first, then by id.
|
||||||
const reports = [...gdelt.reports.values()]
|
const reports = [...gdelt.reports.values()]
|
||||||
.filter((r) => r.publishedAt >= dayAgo)
|
.filter((r) => r.publishedAt >= dayAgo)
|
||||||
.sort((a, b) => b.publishedAt.localeCompare(a.publishedAt))
|
.sort(
|
||||||
|
(a, b) =>
|
||||||
|
b.publishedAt.localeCompare(a.publishedAt) ||
|
||||||
|
b.mentions - a.mentions ||
|
||||||
|
a.id.localeCompare(b.id),
|
||||||
|
)
|
||||||
.slice(0, MAX_GDELT_REPORTS);
|
.slice(0, MAX_GDELT_REPORTS);
|
||||||
if (reports.length !== gdelt.reports.size) {
|
if (reports.length !== gdelt.reports.size) {
|
||||||
const kept = new Set(reports);
|
const kept = new Set(reports);
|
||||||
|
|||||||
Reference in new issue
Block a user