mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add missing indexes, fix order of results
This commit is contained in:
parent
ab7a0e06c7
commit
1482ee148e
2 changed files with 16 additions and 3 deletions
|
|
@ -112,7 +112,7 @@ const accountLookupController: AppController = async (c) => {
|
||||||
|
|
||||||
const accountSearchQuerySchema = z.object({
|
const accountSearchQuerySchema = z.object({
|
||||||
q: z.string().transform(decodeURIComponent),
|
q: z.string().transform(decodeURIComponent),
|
||||||
resolve: booleanParamSchema.optional().transform(Boolean),
|
resolve: booleanParamSchema.optional(),
|
||||||
following: z.boolean().default(false),
|
following: z.boolean().default(false),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -148,7 +148,13 @@ const accountSearchController: AppController = async (c) => {
|
||||||
const following = viewerPubkey ? await getFollowedPubkeys(viewerPubkey) : new Set<string>();
|
const following = viewerPubkey ? await getFollowedPubkeys(viewerPubkey) : new Set<string>();
|
||||||
const authors = [...await getPubkeysBySearch(kysely, { q: query, limit, offset: 0, following })];
|
const authors = [...await getPubkeysBySearch(kysely, { q: query, limit, offset: 0, following })];
|
||||||
const profiles = await store.query([{ kinds: [0], authors, limit }], { signal });
|
const profiles = await store.query([{ kinds: [0], authors, limit }], { signal });
|
||||||
events.push(...profiles);
|
|
||||||
|
for (const pubkey of authors) {
|
||||||
|
const profile = profiles.find((event) => event.pubkey === pubkey);
|
||||||
|
if (profile) {
|
||||||
|
events.push(profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const accounts = await hydrateEvents({ events, store, signal })
|
const accounts = await hydrateEvents({ events, store, signal })
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Kysely } from 'kysely';
|
import { Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
export async function up(db: Kysely<any>): Promise<void> {
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
|
|
@ -6,8 +6,15 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||||
.materialized()
|
.materialized()
|
||||||
.as(db.selectFrom('author_stats').select(['pubkey', 'followers_count', 'search']).orderBy('followers_count desc'))
|
.as(db.selectFrom('author_stats').select(['pubkey', 'followers_count', 'search']).orderBy('followers_count desc'))
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
await sql`CREATE INDEX top_authors_search_idx ON top_authors USING GIN (search gin_trgm_ops)`.execute(db);
|
||||||
|
|
||||||
|
await db.schema.createIndex('top_authors_pubkey_idx').on('top_authors').column('pubkey').execute();
|
||||||
|
|
||||||
|
await db.schema.dropIndex('author_stats_search_idx').execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(db: Kysely<unknown>): Promise<void> {
|
export async function down(db: Kysely<unknown>): Promise<void> {
|
||||||
await db.schema.dropView('top_authors').execute();
|
await db.schema.dropView('top_authors').execute();
|
||||||
|
await sql`CREATE INDEX author_stats_search_idx ON author_stats USING GIN (search gin_trgm_ops)`.execute(db);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue