Merge branch 'zaps-trends' into 'main'

Zaps trends

See merge request soapbox-pub/ditto!361
This commit is contained in:
Alex Gleason 2024-06-06 03:02:43 +00:00
commit 20b11b686b
1 changed files with 36 additions and 8 deletions

View File

@ -9,8 +9,15 @@ 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(
console.info(`Updating trending #${tagName}...`); l: string,
tagName: string,
kinds: number[],
limit: number,
extra = '',
aliases?: string[],
) {
console.info(`Updating trending ${l}...`);
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),
);
} }