Add quotes count
This commit is contained in:
parent
a9dcebd7c2
commit
22c840092f
|
@ -21,6 +21,7 @@ interface EventStatsRow {
|
|||
replies_count: number;
|
||||
reposts_count: number;
|
||||
reactions_count: number;
|
||||
quotes_count: number;
|
||||
reactions: string;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import { Kysely } from 'kysely';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
.alterTable('event_stats')
|
||||
.addColumn('quotes_count', 'integer', (col) => col.notNull().defaultTo(0))
|
||||
.execute();
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema.alterTable('event_stats').dropColumn('quotes_count').execute();
|
||||
}
|
|
@ -11,6 +11,7 @@ export interface AuthorStats {
|
|||
export interface EventStats {
|
||||
replies_count: number;
|
||||
reposts_count: number;
|
||||
quotes_count: number;
|
||||
reactions: Record<string, number>;
|
||||
}
|
||||
|
||||
|
|
|
@ -297,6 +297,7 @@ async function gatherEventStats(events: DittoEvent[]): Promise<DittoTables['even
|
|||
reposts_count: Math.max(0, row.reposts_count),
|
||||
replies_count: Math.max(0, row.replies_count),
|
||||
reactions_count: Math.max(0, row.reactions_count),
|
||||
quotes_count: Math.max(0, row.quotes_count),
|
||||
reactions: row.reactions,
|
||||
}));
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { Kysely, UpdateObject } from 'kysely';
|
|||
import { SetRequired } from 'type-fest';
|
||||
|
||||
import { DittoTables } from '@/db/DittoTables.ts';
|
||||
import { findReplyTag, getTagSet } from '@/utils/tags.ts';
|
||||
import { findQuoteTag, findReplyTag, getTagSet } from '@/utils/tags.ts';
|
||||
import { Conf } from '@/config.ts';
|
||||
|
||||
interface UpdateStatsOpts {
|
||||
|
@ -34,14 +34,24 @@ export async function updateStats({ event, kysely, store, x = 1 }: UpdateStatsOp
|
|||
async function handleEvent1(kysely: Kysely<DittoTables>, event: NostrEvent, x: number): Promise<void> {
|
||||
await updateAuthorStats(kysely, event.pubkey, ({ notes_count }) => ({ notes_count: Math.max(0, notes_count + x) }));
|
||||
|
||||
const inReplyToId = findReplyTag(event.tags)?.[1];
|
||||
if (inReplyToId) {
|
||||
const replyId = findReplyTag(event.tags)?.[1];
|
||||
const quoteId = findQuoteTag(event.tags)?.[1];
|
||||
|
||||
if (replyId) {
|
||||
await updateEventStats(
|
||||
kysely,
|
||||
inReplyToId,
|
||||
replyId,
|
||||
({ replies_count }) => ({ replies_count: Math.max(0, replies_count + x) }),
|
||||
);
|
||||
}
|
||||
|
||||
if (quoteId) {
|
||||
await updateEventStats(
|
||||
kysely,
|
||||
quoteId,
|
||||
({ quotes_count }) => ({ quotes_count: Math.max(0, quotes_count + x) }),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** Update stats for kind 3 event. */
|
||||
|
@ -208,6 +218,7 @@ export async function updateEventStats(
|
|||
replies_count: 0,
|
||||
reposts_count: 0,
|
||||
reactions_count: 0,
|
||||
quotes_count: 0,
|
||||
reactions: '{}',
|
||||
};
|
||||
|
||||
|
|
|
@ -125,6 +125,7 @@ async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise<
|
|||
pleroma: {
|
||||
emoji_reactions: reactions,
|
||||
expires_at: !isNaN(expiresAt.getTime()) ? expiresAt.toISOString() : undefined,
|
||||
quotes_count: event.event_stats?.quotes_count ?? 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue