From 665d09214cb99b96f31fb3b262da0e35d132b906 Mon Sep 17 00:00:00 2001 From: Leandro Facchinetti Date: Fri, 12 Mar 2021 10:10:53 +0000 Subject: [PATCH] --- src/index.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index a35456d..822d0cf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -476,16 +476,18 @@ export default function killTheNewsletter( sql`SELECT "id" FROM "feeds" WHERE "reference" = ${feedReference}` ); if (feed === undefined) continue; - database.run( - sql` - INSERT INTO "entries" ("feed", "title", "author", "content") - VALUES (${feed.id}, ${subject}, ${from}, ${body}) - ` - ); - while (renderFeed(feedReference)!.length > 500_000) + database.executeTransaction(() => { database.run( - sql`DELETE FROM "entries" WHERE "feed" = ${feed.id} ORDER BY "createdAt" ASC LIMIT 1` + sql` + INSERT INTO "entries" ("feed", "title", "author", "content") + VALUES (${feed.id}, ${subject}, ${from}, ${body}) + ` ); + while (renderFeed(feedReference)!.length > 500_000) + database.run( + sql`DELETE FROM "entries" WHERE "feed" = ${feed.id} ORDER BY "createdAt" ASC LIMIT 1` + ); + }); } callback(); } catch (error) {