Trending Zaps
This commit is contained in:
parent
d6085ba3e2
commit
fb7b5b6056
42
src/cron.ts
42
src/cron.ts
|
@ -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),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue