Trends: track based on the event's created_at date, instead of whenever the row was inserted
This commit is contained in:
parent
79ec5dd4e0
commit
7c8aa88069
|
@ -1,7 +1,7 @@
|
|||
import { Conf } from '@/config.ts';
|
||||
import { relayInit } from '@/deps.ts';
|
||||
import { trends } from '@/trends.ts';
|
||||
import { nostrNow } from '@/utils.ts';
|
||||
import { nostrDate, nostrNow } from '@/utils.ts';
|
||||
|
||||
import type { Event } from '@/event.ts';
|
||||
|
||||
|
@ -23,12 +23,14 @@ function handleEvent(event: Event): void {
|
|||
|
||||
/** Track whenever a hashtag is used, for processing trending tags. */
|
||||
function trackHashtags(event: Event): void {
|
||||
const date = nostrDate(event.created_at);
|
||||
|
||||
const tags = event.tags
|
||||
.filter((tag) => tag[0] === 't')
|
||||
.map((tag) => tag[1]);
|
||||
|
||||
try {
|
||||
trends.addTagUsages(event.pubkey, tags);
|
||||
trends.addTagUsages(event.pubkey, tags, date);
|
||||
} catch (_e) {
|
||||
// do nothing
|
||||
}
|
||||
|
|
|
@ -54,14 +54,13 @@ class TrendsDB {
|
|||
}));
|
||||
}
|
||||
|
||||
addTagUsages(pubkey: string, hashtags: string[]): void {
|
||||
addTagUsages(pubkey: string, hashtags: string[], date = new Date()): void {
|
||||
const pubkey8 = hexIdSchema.parse(pubkey).substring(0, 8);
|
||||
const tags = hashtagSchema.array().min(1).parse(hashtags);
|
||||
const now = new Date();
|
||||
|
||||
this.#db.query(
|
||||
'INSERT INTO tag_usages (tag, pubkey8, inserted_at) VALUES ' + tags.map(() => '(?, ?, ?)').join(', '),
|
||||
tags.map((tag) => [tag, pubkey8, now]).flat(),
|
||||
tags.map((tag) => [tag, pubkey8, date]).flat(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue