simplify db schema + pagination (#94)
This commit is contained in:
parent
12073636c7
commit
3e3f846a9c
@ -1,4 +1,3 @@
|
||||
import { InvalidRequestError } from '@atproto/xrpc-server'
|
||||
import { QueryParams } from '../lexicon/types/app/bsky/feed/getFeedSkeleton'
|
||||
import { AppContext } from '../config'
|
||||
|
||||
@ -14,15 +13,8 @@ export const handler = async (ctx: AppContext, params: QueryParams) => {
|
||||
.limit(params.limit)
|
||||
|
||||
if (params.cursor) {
|
||||
const [indexedAt, cid] = params.cursor.split('::')
|
||||
if (!indexedAt || !cid) {
|
||||
throw new InvalidRequestError('malformed cursor')
|
||||
}
|
||||
const timeStr = new Date(parseInt(indexedAt, 10)).toISOString()
|
||||
builder = builder
|
||||
.where('post.indexedAt', '<', timeStr)
|
||||
.orWhere((qb) => qb.where('post.indexedAt', '=', timeStr))
|
||||
.where('post.cid', '<', cid)
|
||||
const timeStr = new Date(parseInt(params.cursor, 10)).toISOString()
|
||||
builder = builder.where('post.indexedAt', '<', timeStr)
|
||||
}
|
||||
const res = await builder.execute()
|
||||
|
||||
@ -33,7 +25,7 @@ export const handler = async (ctx: AppContext, params: QueryParams) => {
|
||||
let cursor: string | undefined
|
||||
const last = res.at(-1)
|
||||
if (last) {
|
||||
cursor = `${new Date(last.indexedAt).getTime()}::${last.cid}`
|
||||
cursor = new Date(last.indexedAt).getTime().toString(10)
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -14,8 +14,6 @@ migrations['001'] = {
|
||||
.createTable('post')
|
||||
.addColumn('uri', 'varchar', (col) => col.primaryKey())
|
||||
.addColumn('cid', 'varchar', (col) => col.notNull())
|
||||
.addColumn('replyParent', 'varchar')
|
||||
.addColumn('replyRoot', 'varchar')
|
||||
.addColumn('indexedAt', 'varchar', (col) => col.notNull())
|
||||
.execute()
|
||||
await db.schema
|
||||
|
@ -6,8 +6,6 @@ export type DatabaseSchema = {
|
||||
export type Post = {
|
||||
uri: string
|
||||
cid: string
|
||||
replyParent: string | null
|
||||
replyRoot: string | null
|
||||
indexedAt: string
|
||||
}
|
||||
|
||||
|
@ -27,8 +27,6 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
|
||||
return {
|
||||
uri: create.uri,
|
||||
cid: create.cid,
|
||||
replyParent: create.record?.reply?.parent.uri ?? null,
|
||||
replyRoot: create.record?.reply?.root.uri ?? null,
|
||||
indexedAt: new Date().toISOString(),
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user