Add TrendsWorker for tracking/querying trending tags with a Web Worker

This commit is contained in:
Alex Gleason
2023-12-04 16:33:02 -06:00
parent 3169ad0a69
commit d569dfd5b5
7 changed files with 104 additions and 86 deletions

View File

@@ -10,8 +10,8 @@ import { publish } from '@/pool.ts';
import { isLocallyFollowed } from '@/queries.ts';
import { Sub } from '@/subs.ts';
import { getTagSet } from '@/tags.ts';
import { trends } from '@/trends.ts';
import { eventAge, isRelay, nostrDate, Time } from '@/utils.ts';
import { TrendsWorker } from '@/workers/trends.ts';
import { verifySignatureWorker } from '@/workers/verify.ts';
import type { EventData } from '@/types.ts';
@@ -90,7 +90,7 @@ async function processDeletions(event: Event): Promise<void> {
}
/** Track whenever a hashtag is used, for processing trending tags. */
function trackHashtags(event: Event): void {
async function trackHashtags(event: Event): Promise<void> {
const date = nostrDate(event.created_at);
const tags = event.tags
@@ -102,7 +102,7 @@ function trackHashtags(event: Event): void {
try {
console.info('tracking tags:', tags);
trends.addTagUsages(event.pubkey, tags, date);
await TrendsWorker.addTagUsages(event.pubkey, tags, date);
} catch (_e) {
// do nothing
}