Add back reactions_count column so trending can still work
This commit is contained in:
parent
f7c9a96719
commit
c6dea07ac3
|
@ -19,6 +19,7 @@ interface EventStatsRow {
|
|||
event_id: string;
|
||||
replies_count: number;
|
||||
reposts_count: number;
|
||||
reactions_count: number;
|
||||
reactions: string;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,8 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||
.alterTable('event_stats')
|
||||
.addColumn('reactions', 'text', (col) => col.defaultTo('{}'))
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.alterTable('event_stats')
|
||||
.dropColumn('reactions_count')
|
||||
.execute();
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema.alterTable('event_stats').dropColumn('reactions').execute();
|
||||
await db.schema.alterTable('event_stats').addColumn('reactions_count', 'integer').execute();
|
||||
}
|
||||
|
|
|
@ -319,6 +319,7 @@ async function gatherEventStats(events: DittoEvent[]): Promise<DittoTables['even
|
|||
event_id: row.event_id,
|
||||
reposts_count: Math.max(0, row.reposts_count),
|
||||
replies_count: Math.max(0, row.replies_count),
|
||||
reactions_count: Math.max(0, row.reactions_count),
|
||||
reactions: row.reactions,
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -120,6 +120,7 @@ Deno.test('updateStats with kind 7 increments reactions count', async () => {
|
|||
const stats = await getEventStats(db.kysely, note.id);
|
||||
|
||||
assertEquals(stats!.reactions, JSON.stringify({ '+': 1, '😂': 1 }));
|
||||
assertEquals(stats!.reactions_count, 2);
|
||||
});
|
||||
|
||||
Deno.test('updateStats with kind 5 decrements reactions count', async () => {
|
||||
|
|
|
@ -103,8 +103,12 @@ async function handleEvent7(kysely: Kysely<DittoTables>, event: NostrEvent, x: n
|
|||
}
|
||||
}
|
||||
|
||||
// Total reactions count.
|
||||
const count = Object.values(data).reduce((result, value) => result + value, 0);
|
||||
|
||||
return {
|
||||
reactions: JSON.stringify(data),
|
||||
reactions_count: count,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -142,7 +146,7 @@ export async function updateAuthorStats(
|
|||
pubkey: string,
|
||||
fn: (prev: DittoTables['author_stats']) => UpdateObject<DittoTables, 'author_stats'>,
|
||||
): Promise<void> {
|
||||
const empty = {
|
||||
const empty: DittoTables['author_stats'] = {
|
||||
pubkey,
|
||||
followers_count: 0,
|
||||
following_count: 0,
|
||||
|
@ -183,7 +187,7 @@ export async function updateEventStats(
|
|||
eventId: string,
|
||||
fn: (prev: DittoTables['event_stats']) => UpdateObject<DittoTables, 'event_stats'>,
|
||||
): Promise<void> {
|
||||
const empty = {
|
||||
const empty: DittoTables['event_stats'] = {
|
||||
event_id: eventId,
|
||||
replies_count: 0,
|
||||
reposts_count: 0,
|
||||
|
|
Loading…
Reference in New Issue