Never let stats be less than 0
This commit is contained in:
parent
5aacbe7af5
commit
251500fba1
|
@ -251,11 +251,19 @@ async function gatherAuthorStats(events: DittoEvent[]): Promise<DittoTables['aut
|
||||||
}
|
}
|
||||||
|
|
||||||
const kysely = await DittoDB.getInstance();
|
const kysely = await DittoDB.getInstance();
|
||||||
return kysely
|
|
||||||
|
const rows = await kysely
|
||||||
.selectFrom('author_stats')
|
.selectFrom('author_stats')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.where('pubkey', 'in', [...pubkeys])
|
.where('pubkey', 'in', [...pubkeys])
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
return rows.map((row) => ({
|
||||||
|
pubkey: row.pubkey,
|
||||||
|
followers_count: Math.max(0, row.followers_count),
|
||||||
|
following_count: Math.max(0, row.following_count),
|
||||||
|
notes_count: Math.max(0, row.notes_count),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Collect event stats from the events. */
|
/** Collect event stats from the events. */
|
||||||
|
@ -271,11 +279,19 @@ async function gatherEventStats(events: DittoEvent[]): Promise<DittoTables['even
|
||||||
}
|
}
|
||||||
|
|
||||||
const kysely = await DittoDB.getInstance();
|
const kysely = await DittoDB.getInstance();
|
||||||
return kysely
|
|
||||||
|
const rows = await kysely
|
||||||
.selectFrom('event_stats')
|
.selectFrom('event_stats')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.where('event_id', 'in', [...ids])
|
.where('event_id', 'in', [...ids])
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
return rows.map((row) => ({
|
||||||
|
event_id: row.event_id,
|
||||||
|
reposts_count: Math.max(0, row.reposts_count),
|
||||||
|
reactions_count: Math.max(0, row.reactions_count),
|
||||||
|
replies_count: Math.max(0, row.replies_count),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return a normalized event without any non-standard keys. */
|
/** Return a normalized event without any non-standard keys. */
|
||||||
|
|
Loading…
Reference in New Issue