From 3e3f846a9cb897006037c5241c3dd8fa279341c7 Mon Sep 17 00:00:00 2001 From: Daniel Holmgren Date: Mon, 8 Jul 2024 12:59:26 -0500 Subject: [PATCH] simplify db schema + pagination (#94) --- src/algos/whats-alf.ts | 14 +++----------- src/db/migrations.ts | 2 -- src/db/schema.ts | 2 -- src/subscription.ts | 2 -- 4 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/algos/whats-alf.ts b/src/algos/whats-alf.ts index a131547..ece91fa 100644 --- a/src/algos/whats-alf.ts +++ b/src/algos/whats-alf.ts @@ -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 { diff --git a/src/db/migrations.ts b/src/db/migrations.ts index 9660078..be720ee 100644 --- a/src/db/migrations.ts +++ b/src/db/migrations.ts @@ -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 diff --git a/src/db/schema.ts b/src/db/schema.ts index 8b2455d..4f54e2c 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -6,8 +6,6 @@ export type DatabaseSchema = { export type Post = { uri: string cid: string - replyParent: string | null - replyRoot: string | null indexedAt: string } diff --git a/src/subscription.ts b/src/subscription.ts index b3a141e..3589baa 100644 --- a/src/subscription.ts +++ b/src/subscription.ts @@ -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(), } })