Skip to content

Commit

Permalink
Remove legacy repo sync impl (bluesky-social#1570)
Browse files Browse the repository at this point in the history
remove legacy repo sync impl
  • Loading branch information
dholms authored and mloar committed Sep 25, 2023
1 parent 51c0021 commit 64cf758
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 55 deletions.
22 changes: 8 additions & 14 deletions packages/pds/src/api/com/atproto/sync/deprecated/getCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import SqlRepoStorage, {
} from '../../../../../sql-repo-storage'
import AppContext from '../../../../../context'
import { isUserOrAdmin } from '../../../../../auth'
import { getFullRepo } from '@atproto/repo'

export default function (server: Server, ctx: AppContext) {
server.com.atproto.sync.getCheckout({
Expand All @@ -24,20 +23,15 @@ export default function (server: Server, ctx: AppContext) {
}

const storage = new SqlRepoStorage(ctx.db, did)
const head = await storage.getRoot()
if (!head) {
throw new InvalidRequestError(`Could not find repo for DID: ${did}`)
let carStream: AsyncIterable<Uint8Array>
try {
carStream = await storage.getCarStream()
} catch (err) {
if (err instanceof RepoRootNotFoundError) {
throw new InvalidRequestError(`Could not find repo for DID: ${did}`)
}
throw err
}
const carStream = getFullRepo(storage, head)
// let carStream: AsyncIterable<Uint8Array>
// try {
// carStream = await storage.getCarStream()
// } catch (err) {
// if (err instanceof RepoRootNotFoundError) {
// throw new InvalidRequestError(`Could not find repo for DID: ${did}`)
// }
// throw err
// }

return {
encoding: 'application/vnd.ipld.car',
Expand Down
4 changes: 1 addition & 3 deletions packages/pds/src/api/com/atproto/sync/getRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export default function (server: Server, ctx: AppContext) {
const storage = new SqlRepoStorage(ctx.db, did)
let carStream: AsyncIterable<Uint8Array>
try {
carStream = since
? await storage.getCarStream(since)
: await storage.getCarStreamLegacy()
carStream = await storage.getCarStream(since)
} catch (err) {
if (err instanceof RepoRootNotFoundError) {
throw new InvalidRequestError(`Could not find repo for DID: ${did}`)
Expand Down
38 changes: 0 additions & 38 deletions packages/pds/src/sql-repo-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,44 +206,6 @@ export class SqlRepoStorage extends ReadableBlockstore implements RepoStorage {
}
}

async getCarStreamLegacy() {
const root = await this.getRoot()
if (!root) {
throw new RepoRootNotFoundError()
}
return writeCarStream(root, async (car) => {
let cursor: CID | undefined = undefined
do {
const res = await this.getBlockRangeLegacy(cursor)
for (const row of res) {
await car.put({
cid: CID.parse(row.cid),
bytes: row.content,
})
}
const lastRow = res.at(-1)
if (lastRow) {
cursor = CID.parse(lastRow.cid)
} else {
cursor = undefined
}
} while (cursor)
})
}

async getBlockRangeLegacy(cursor?: CID) {
let builder = this.db.db
.selectFrom('ipld_block')
.where('creator', '=', this.did)
.select(['cid', 'content'])
.orderBy('cid', 'asc')
.limit(500)
if (cursor) {
builder = builder.where('cid', '>', cursor.toString())
}
return builder.execute()
}

async getCarStream(since?: string) {
const root = await this.getRoot()
if (!root) {
Expand Down

0 comments on commit 64cf758

Please sign in to comment.