Merge branch 'zaps-trends' into 'main'
Zaps trends See merge request soapbox-pub/ditto!361
This commit is contained in:
commit
20b11b686b
44
src/cron.ts
44
src/cron.ts
|
@ -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),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue