mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
trends: disable for now
This commit is contained in:
parent
c8bec9b4b7
commit
e6b18e7d95
1 changed files with 24 additions and 36 deletions
|
|
@ -1,10 +1,8 @@
|
||||||
import { NPostgresSchema } from '@nostrify/db';
|
|
||||||
import { NostrFilter } from '@nostrify/nostrify';
|
import { NostrFilter } from '@nostrify/nostrify';
|
||||||
import { Stickynotes } from '@soapbox/stickynotes';
|
import { Stickynotes } from '@soapbox/stickynotes';
|
||||||
import { Kysely } from 'kysely';
|
|
||||||
|
|
||||||
import { Conf } from '@/config.ts';
|
import { Conf } from '@/config.ts';
|
||||||
import { DittoDB } from '@/db/DittoDB.ts';
|
import { DittoDatabase, 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';
|
||||||
import { Time } from '@/utils/time.ts';
|
import { Time } from '@/utils/time.ts';
|
||||||
|
|
@ -14,7 +12,7 @@ const console = new Stickynotes('ditto:trends');
|
||||||
/** Get trending tag values for a given tag in the given time frame. */
|
/** Get trending tag values for a given tag in the given time frame. */
|
||||||
export async function getTrendingTagValues(
|
export async function getTrendingTagValues(
|
||||||
/** Kysely instance to execute queries on. */
|
/** Kysely instance to execute queries on. */
|
||||||
kysely: Kysely<NPostgresSchema>,
|
db: DittoDatabase,
|
||||||
/** Tag name to filter by, eg `t` or `r`. */
|
/** Tag name to filter by, eg `t` or `r`. */
|
||||||
tagNames: string[],
|
tagNames: string[],
|
||||||
/** Filter of eligible events. */
|
/** Filter of eligible events. */
|
||||||
|
|
@ -40,39 +38,29 @@ export async function getTrendingTagValues(
|
||||||
COUNT(DISTINCT nostr_events.pubkey) DESC
|
COUNT(DISTINCT nostr_events.pubkey) DESC
|
||||||
LIMIT 20;
|
LIMIT 20;
|
||||||
*/
|
*/
|
||||||
let query = kysely
|
|
||||||
.selectFrom((eb) => [
|
|
||||||
'nostr_events',
|
|
||||||
eb.from('jsonb_each_text', ['nostr_events.tags_index'], 'kv'),
|
|
||||||
eb.from('jsonb_array_elements_text', ['kv.value::jsonb'], 'element'),
|
|
||||||
])
|
|
||||||
.select(({ fn }) => [
|
|
||||||
fn('lower', ['element.value']).as('value'),
|
|
||||||
])
|
|
||||||
.where('nostr_tags.name', 'in', tagNames)
|
|
||||||
.groupBy('nostr_tags.value')
|
|
||||||
.orderBy((c) => c.fn.agg('count', ['nostr_tags.pubkey']).distinct(), 'desc');
|
|
||||||
|
|
||||||
if (filter.kinds) {
|
return [];
|
||||||
query = query.where('kind', 'in', filter.kinds);
|
|
||||||
}
|
|
||||||
if (typeof filter.since === 'number') {
|
|
||||||
query = query.where('created_at', '>=', filter.since);
|
|
||||||
}
|
|
||||||
if (typeof filter.until === 'number') {
|
|
||||||
query = query.where('created_at', '<=', filter.until);
|
|
||||||
}
|
|
||||||
if (typeof filter.limit === 'number') {
|
|
||||||
query = query.limit(filter.limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
const rows = await query.execute();
|
// if (filter.kinds) {
|
||||||
|
// query = query.where('kind', 'in', filter.kinds);
|
||||||
|
// }
|
||||||
|
// if (typeof filter.since === 'number') {
|
||||||
|
// query = query.where('created_at', '>=', filter.since);
|
||||||
|
// }
|
||||||
|
// if (typeof filter.until === 'number') {
|
||||||
|
// query = query.where('created_at', '<=', filter.until);
|
||||||
|
// }
|
||||||
|
// if (typeof filter.limit === 'number') {
|
||||||
|
// query = query.limit(filter.limit);
|
||||||
|
// }
|
||||||
|
|
||||||
return rows.map((row) => ({
|
// const rows = await query.execute();
|
||||||
value: row.value,
|
|
||||||
authors: Number(row.authors),
|
// return rows.map((row) => ({
|
||||||
uses: Number(row.uses),
|
// value: row.value,
|
||||||
}));
|
// authors: Number(row.authors),
|
||||||
|
// uses: Number(row.uses),
|
||||||
|
// }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get trending tags and publish an event with them. */
|
/** Get trending tags and publish an event with them. */
|
||||||
|
|
@ -85,7 +73,7 @@ export async function updateTrendingTags(
|
||||||
aliases?: string[],
|
aliases?: string[],
|
||||||
) {
|
) {
|
||||||
console.info(`Updating trending ${l}...`);
|
console.info(`Updating trending ${l}...`);
|
||||||
const kysely = await DittoDB.getInstance();
|
const db = await DittoDB.getInstance();
|
||||||
const signal = AbortSignal.timeout(1000);
|
const signal = AbortSignal.timeout(1000);
|
||||||
|
|
||||||
const yesterday = Math.floor((Date.now() - Time.days(1)) / 1000);
|
const yesterday = Math.floor((Date.now() - Time.days(1)) / 1000);
|
||||||
|
|
@ -94,7 +82,7 @@ export async function updateTrendingTags(
|
||||||
const tagNames = aliases ? [tagName, ...aliases] : [tagName];
|
const tagNames = aliases ? [tagName, ...aliases] : [tagName];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const trends = await getTrendingTagValues(kysely, tagNames, {
|
const trends = await getTrendingTagValues(db, tagNames, {
|
||||||
kinds,
|
kinds,
|
||||||
since: yesterday,
|
since: yesterday,
|
||||||
until: now,
|
until: now,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue