diff --git a/src/server.ts b/src/server.ts index 059b805..bbcf69f 100644 --- a/src/server.ts +++ b/src/server.ts @@ -30,7 +30,7 @@ export class FeedGenerator { static create(config?: Partial) { const cfg: Config = { port: config?.port ?? 3000, - sqliteLocation: config?.sqliteLocation ?? 'test.sqlite', + sqliteLocation: config?.sqliteLocation ?? ':memory:', subscriptionEndpoint: config?.subscriptionEndpoint ?? 'wss://bsky.social', serviceDid: config?.serviceDid ?? 'did:example:test', } diff --git a/src/subscription.ts b/src/subscription.ts index 649f7ed..0aaf94e 100644 --- a/src/subscription.ts +++ b/src/subscription.ts @@ -8,6 +8,11 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase { async handleEvent(evt: RepoEvent) { if (!isCommit(evt)) return const ops = await getOpsByType(evt) + if (ops.posts.creates.length > 0) { + for (const op of ops.posts.creates) { + console.log(op.record.text) + } + } const postsToDelete = ops.posts.deletes.map((del) => del.uri) const postsToCreate = ops.posts.creates .filter((create) => { diff --git a/src/util/subscription.ts b/src/util/subscription.ts index 3eee79e..e3c0111 100644 --- a/src/util/subscription.ts +++ b/src/util/subscription.ts @@ -36,7 +36,6 @@ export abstract class FirehoseSubscriptionBase { abstract handleEvent(evt: RepoEvent): Promise async run() { - await this.ensureCursor() for await (const evt of this.sub) { try { await this.handleEvent(evt) @@ -50,17 +49,6 @@ export abstract class FirehoseSubscriptionBase { } } - async ensureCursor() { - await this.db - .insertInto('sub_state') - .values({ - service: this.service, - cursor: 0, - }) - .onConflict((oc) => oc.doNothing()) - .execute() - } - async updateCursor(cursor: number) { await this.db .updateTable('sub_state') @@ -69,13 +57,13 @@ export abstract class FirehoseSubscriptionBase { .execute() } - async getCursor(): Promise<{ cursor: number }> { + async getCursor(): Promise<{ cursor?: number }> { const res = await this.db .selectFrom('sub_state') .selectAll() .where('service', '=', this.service) .executeTakeFirst() - return res ? { cursor: res.cursor } : { cursor: 0 } + return res ? { cursor: res.cursor } : {} } }