forked from bluesky-social/atproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove post hierarchy indexing from bsky appview (bluesky-social#1257)
* remove post_hierarchy from db model and indexing in bsky appview * update bsky appview getPostThread to use recursive query to build thread * add covering index to speed-up descendents query * tidy post/notification processing w/o post_hierarchy * tidy, disallow infinitely following reply cycles
- Loading branch information
Showing
9 changed files
with
183 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/bsky/src/db/migrations/20230629T220835893Z-remove-post-hierarchy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Kysely, sql } from 'kysely' | ||
|
||
export async function up(db: Kysely<unknown>): Promise<void> { | ||
await db.schema.dropTable('post_hierarchy').execute() | ||
// recreate index that calculates e.g. "replyCount", turning it into a covering index | ||
// for uri so that recursive query for post descendents can use an index-only scan. | ||
await db.schema.dropIndex('post_replyparent_idx').execute() | ||
await sql`create index "post_replyparent_idx" on "post" ("replyParent") include ("uri")`.execute( | ||
db, | ||
) | ||
} | ||
|
||
export async function down(db: Kysely<unknown>): Promise<void> { | ||
await db.schema | ||
.createTable('post_hierarchy') | ||
.addColumn('uri', 'varchar', (col) => col.notNull()) | ||
.addColumn('ancestorUri', 'varchar', (col) => col.notNull()) | ||
.addColumn('depth', 'integer', (col) => col.notNull()) | ||
.addPrimaryKeyConstraint('post_hierarchy_pkey', ['uri', 'ancestorUri']) | ||
.execute() | ||
await db.schema | ||
.createIndex('post_hierarchy_ancestoruri_idx') | ||
.on('post_hierarchy') | ||
.column('ancestorUri') | ||
.execute() | ||
await db.schema.dropIndex('post_replyparent_idx').execute() | ||
await db.schema | ||
.createIndex('post_replyparent_idx') | ||
.on('post') | ||
.column('replyParent') | ||
.execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.