Trending Zaps

This commit is contained in:
Alex Gleason 2024-06-05 21:37:07 -05:00
parent d6085ba3e2
commit fb7b5b6056
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 35 additions and 7 deletions

View File

@ -9,7 +9,14 @@ import { Time } from '@/utils/time.ts';
const console = new Stickynotes('ditto:trends'); const console = new Stickynotes('ditto:trends');
async function updateTrendingTags(tagName: string, kinds: number[], limit: number, extra = '', aliases?: string[]) { async function updateTrendingTags(
tagName: string,
l: string,
kinds: number[],
limit: number,
extra = '',
aliases?: string[],
) {
console.info(`Updating trending #${tagName}...`); console.info(`Updating trending #${tagName}...`);
const kysely = await DittoDB.getInstance(); const kysely = await DittoDB.getInstance();
const signal = AbortSignal.timeout(1000); const signal = AbortSignal.timeout(1000);
@ -37,20 +44,41 @@ async function updateTrendingTags(tagName: string, kinds: number[], limit: numbe
content: '', content: '',
tags: [ tags: [
['L', 'pub.ditto.trends'], ['L', 'pub.ditto.trends'],
['l', `#${tagName}`, 'pub.ditto.trends'], ['l', l, 'pub.ditto.trends'],
...trends.map(({ value, authors, uses }) => [tagName, value, extra, authors.toString(), uses.toString()]), ...trends.map(({ value, authors, uses }) => [tagName, value, extra, authors.toString(), uses.toString()]),
], ],
created_at: Math.floor(Date.now() / 1000), created_at: Math.floor(Date.now() / 1000),
}); });
await handleEvent(label, signal); await handleEvent(label, signal);
console.info(`Trending #${tagName} updated.`); console.info(`Trending ${l} updated.`);
} }
/** Start cron jobs for the application. */ /** Start cron jobs for the application. */
export function cron() { export function cron() {
Deno.cron('update trending pubkeys', '0 * * * *', () => updateTrendingTags('p', [1, 3], 40, Conf.relay)); Deno.cron(
Deno.cron('update trending notes', '15 * * * *', () => updateTrendingTags('e', [1, 6, 7], 40, Conf.relay, ['q'])); 'update trending pubkeys',
Deno.cron('update trending hashtags', '30 * * * *', () => updateTrendingTags('t', [1], 20)); '0 * * * *',
Deno.cron('update trending links', '45 * * * *', () => updateTrendingTags('r', [1], 20)); () => updateTrendingTags('#p', 'p', [1, 6, 7, 9735], 40, Conf.relay),
);
Deno.cron(
'update trending zapped events',
'7 * * * *',
() => updateTrendingTags('zapped', 'e', [9735], 40, Conf.relay, ['q']),
);
Deno.cron(
'update trending events',
'15 * * * *',
() => updateTrendingTags('#e', 'e', [1, 6, 7, 9735], 40, Conf.relay, ['q']),
);
Deno.cron(
'update trending hashtags',
'30 * * * *',
() => updateTrendingTags('#t', 't', [1], 20),
);
Deno.cron(
'update trending links',
'45 * * * *',
() => updateTrendingTags('#r', 'r', [1], 20),
);
} }