Skip to content

Commit

Permalink
Merge branch 'main' into simplify-pds
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Oct 1, 2023
2 parents 7e5920f + 3b65224 commit dc0360f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Kysely } from 'kysely'

export async function up(db: Kysely<unknown>): Promise<void> {
await db.schema
.createIndex('like_creator_cursor_idx')
.on('like')
.columns(['creator', 'sortAt', 'cid'])
.execute()
await db.schema
.createIndex('follow_creator_cursor_idx')
.on('follow')
.columns(['creator', 'sortAt', 'cid'])
.execute()
await db.schema
.createIndex('follow_subject_cursor_idx')
.on('follow')
.columns(['subjectDid', 'sortAt', 'cid'])
.execute()

// drop old indices that are superceded by these
await db.schema.dropIndex('like_creator_idx').execute()
await db.schema.dropIndex('follow_subjectdid_idx').execute()
}

export async function down(db: Kysely<unknown>): Promise<void> {
await db.schema
.createIndex('like_creator_idx')
.on('like')
.column('creator')
.execute()
await db.schema
.createIndex('follow_subjectdid_idx')
.on('follow')
.column('subjectDid')
.execute()

await db.schema.dropIndex('like_creator_cursor_idx').execute()
await db.schema.dropIndex('follow_creator_cursor_idx').execute()
await db.schema.dropIndex('follow_subject_cursor_idx').execute()
}
1 change: 1 addition & 0 deletions packages/bsky/src/db/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export * as _20230830T205507322Z from './20230830T205507322Z-suggested-feeds'
export * as _20230904T211011773Z from './20230904T211011773Z-block-lists'
export * as _20230906T222220386Z from './20230906T222220386Z-thread-gating'
export * as _20230920T213858047Z from './20230920T213858047Z-add-tags-to-post'
export * as _20230929T192920807Z from './20230929T192920807Z-record-cursor-indexes'
4 changes: 2 additions & 2 deletions packages/bsky/src/feed-gen/with-friends.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const handler: AlgoHandler = async (

const { ref } = db.db.dynamic

const keyset = new FeedKeyset(ref('post.indexedAt'), ref('post.cid'))
const keyset = new FeedKeyset(ref('post.sortAt'), ref('post.cid'))
const sortFrom = keyset.unpack(cursor)?.primary

let postsQb = feedService
Expand All @@ -24,7 +24,7 @@ const handler: AlgoHandler = async (
.innerJoin('post_agg', 'post_agg.uri', 'post.uri')
.where('post_agg.likeCount', '>=', 5)
.where('follow.creator', '=', requester)
.where('post.indexedAt', '>', getFeedDateThreshold(sortFrom))
.where('post.sortAt', '>', getFeedDateThreshold(sortFrom))

postsQb = paginate(postsQb, { limit, cursor, keyset, tryIndex: true })

Expand Down
6 changes: 0 additions & 6 deletions packages/pds/src/sql-repo-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,6 @@ export class SqlRepoStorage extends ReadableBlockstore implements RepoStorage {
const res = await this.getBlockRange(since, cursor)
await writePromise
writePromise = writeRows(res)
for (const row of res) {
await car.put({
cid: CID.parse(row.cid),
bytes: row.content,
})
}
const lastRow = res.at(-1)
if (lastRow && lastRow.repoRev) {
cursor = {
Expand Down
2 changes: 1 addition & 1 deletion packages/repo/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const readCar = async (
const roots = await car.getRoots()
const blocks = new BlockMap()
for await (const block of verifyIncomingCarBlocks(car.blocks())) {
await blocks.set(block.cid, block.bytes)
blocks.set(block.cid, block.bytes)
}
return {
roots,
Expand Down

0 comments on commit dc0360f

Please sign in to comment.