Support trending links
This commit is contained in:
parent
cd46d63999
commit
7f16a8d556
43
src/cron.ts
43
src/cron.ts
|
@ -1,5 +1,6 @@
|
||||||
import { Stickynotes } from '@soapbox/stickynotes';
|
import { Stickynotes } from '@soapbox/stickynotes';
|
||||||
|
|
||||||
|
import { Conf } from '@/config.ts';
|
||||||
import { DittoDB } from '@/db/DittoDB.ts';
|
import { DittoDB } from '@/db/DittoDB.ts';
|
||||||
import { handleEvent } from '@/pipeline.ts';
|
import { handleEvent } from '@/pipeline.ts';
|
||||||
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
import { AdminSigner } from '@/signers/AdminSigner.ts';
|
||||||
|
@ -21,7 +22,7 @@ async function updateTrendingNotesCache() {
|
||||||
kinds: [1],
|
kinds: [1],
|
||||||
since: yesterday,
|
since: yesterday,
|
||||||
until: now,
|
until: now,
|
||||||
limit: 20,
|
limit: 40,
|
||||||
});
|
});
|
||||||
|
|
||||||
const signer = new AdminSigner();
|
const signer = new AdminSigner();
|
||||||
|
@ -32,7 +33,7 @@ async function updateTrendingNotesCache() {
|
||||||
tags: [
|
tags: [
|
||||||
['L', 'pub.ditto.trends'],
|
['L', 'pub.ditto.trends'],
|
||||||
['l', 'notes', 'pub.ditto.trends'],
|
['l', 'notes', 'pub.ditto.trends'],
|
||||||
...events.map(({ id }) => ['e', id]),
|
...events.map(({ id }) => ['e', id, Conf.relay]),
|
||||||
],
|
],
|
||||||
created_at: Math.floor(Date.now() / 1000),
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
});
|
});
|
||||||
|
@ -63,7 +64,7 @@ async function updateTrendingHashtagsCache() {
|
||||||
tags: [
|
tags: [
|
||||||
['L', 'pub.ditto.trends'],
|
['L', 'pub.ditto.trends'],
|
||||||
['l', 'hashtags', 'pub.ditto.trends'],
|
['l', 'hashtags', 'pub.ditto.trends'],
|
||||||
...hashtags.map(({ value }) => ['t', value]),
|
...hashtags.map(({ value, authors, uses }) => ['t', value, authors.toString(), uses.toString()]),
|
||||||
],
|
],
|
||||||
created_at: Math.floor(Date.now() / 1000),
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
});
|
});
|
||||||
|
@ -72,8 +73,40 @@ async function updateTrendingHashtagsCache() {
|
||||||
console.info('Trending hashtags cache updated.');
|
console.info('Trending hashtags cache updated.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updateTrendingLinksCache() {
|
||||||
|
console.info('Updating trending links cache...');
|
||||||
|
const kysely = await DittoDB.getInstance();
|
||||||
|
const signal = AbortSignal.timeout(1000);
|
||||||
|
|
||||||
|
const yesterday = Math.floor((Date.now() - Time.days(1)) / 1000);
|
||||||
|
const now = Math.floor(Date.now() / 1000);
|
||||||
|
|
||||||
|
const links = await getTrendingTagValues(kysely, 'r', {
|
||||||
|
since: yesterday,
|
||||||
|
until: now,
|
||||||
|
limit: 20,
|
||||||
|
});
|
||||||
|
|
||||||
|
const signer = new AdminSigner();
|
||||||
|
|
||||||
|
const label = await signer.signEvent({
|
||||||
|
kind: 1985,
|
||||||
|
content: '',
|
||||||
|
tags: [
|
||||||
|
['L', 'pub.ditto.trends'],
|
||||||
|
['l', 'links', 'pub.ditto.trends'],
|
||||||
|
...links.map(({ value, authors, uses }) => ['r', value, authors.toString(), uses.toString()]),
|
||||||
|
],
|
||||||
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
|
});
|
||||||
|
|
||||||
|
await handleEvent(label, signal);
|
||||||
|
console.info('Trending links cache updated.');
|
||||||
|
}
|
||||||
|
|
||||||
/** Start cron jobs for the application. */
|
/** Start cron jobs for the application. */
|
||||||
export function cron() {
|
export function cron() {
|
||||||
Deno.cron('update trending notes cache', { minute: { every: 15 } }, updateTrendingNotesCache);
|
Deno.cron('update trending notes cache', '15 * * * *', updateTrendingNotesCache);
|
||||||
Deno.cron('update trending hashtags cache', { dayOfMonth: { every: 1 } }, updateTrendingHashtagsCache);
|
Deno.cron('update trending hashtags cache', '30 * * * *', updateTrendingHashtagsCache);
|
||||||
|
Deno.cron('update trending links cache', '45 * * * *', updateTrendingLinksCache);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue