Make author_stats and event_stats two separate keys on an event

This commit is contained in:
Alex Gleason 2023-12-10 15:40:05 -06:00
parent a48c1e51e1
commit 5415656b4d
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 11 additions and 10 deletions

View File

@ -224,8 +224,9 @@ type AuthorStats = Omit<DittoDB['pubkey_stats'], 'pubkey'>;
type EventStats = Omit<DittoDB['event_stats'], 'event_id'>;
interface DittoEvent<K extends number = number> extends Event<K> {
author?: Event<0> & { stats?: AuthorStats };
stats?: EventStats;
author?: DittoEvent<0>;
author_stats?: AuthorStats;
event_stats?: EventStats;
}
/** Get events for filters from the database. */
@ -263,7 +264,7 @@ async function getFilters<K extends number>(
};
if (typeof row.author_stats_followers_count === 'number') {
event.author.stats = {
event.author.author_stats = {
followers_count: row.author_stats_followers_count,
following_count: row.author_stats_following_count!,
notes_count: row.author_stats_notes_count!,
@ -272,7 +273,7 @@ async function getFilters<K extends number>(
}
if (typeof row.stats_replies_count === 'number') {
event.stats = {
event.event_stats = {
replies_count: row.stats_replies_count,
reposts_count: row.stats_reposts_count!,
reactions_count: row.stats_reactions_count!,

View File

@ -45,8 +45,8 @@ async function renderAccount(
emojis: renderEmojis(event),
fields: [],
follow_requests_count: 0,
followers_count: event.stats?.followers_count ?? 0,
following_count: event.stats?.following_count ?? 0,
followers_count: event.author_stats?.followers_count ?? 0,
following_count: event.author_stats?.following_count ?? 0,
fqn: parsed05?.handle || npub,
header: banner,
header_static: banner,
@ -64,7 +64,7 @@ async function renderAccount(
follow_requests_count: 0,
}
: undefined,
statuses_count: event.stats?.notes_count ?? 0,
statuses_count: event.author_stats?.notes_count ?? 0,
url: Conf.local(`/users/${pubkey}`),
username: parsed05?.nickname || npub.substring(0, 8),
pleroma: {

View File

@ -63,9 +63,9 @@ async function renderStatus(event: eventsDB.DittoEvent<1>, viewerPubkey?: string
spoiler_text: (cw ? cw[1] : subject?.[1]) || '',
visibility: 'public',
language: event.tags.find((tag) => tag[0] === 'lang')?.[1] || null,
replies_count: event.stats?.replies_count ?? 0,
reblogs_count: event.stats?.reposts_count ?? 0,
favourites_count: event.stats?.reactions_count ?? 0,
replies_count: event.event_stats?.replies_count ?? 0,
reblogs_count: event.event_stats?.reposts_count ?? 0,
favourites_count: event.event_stats?.reactions_count ?? 0,
favourited: reactionEvent?.content === '+',
reblogged: Boolean(repostEvent),
muted: false,