⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
bug fix
daniel31x13cb1f42e0a237
diff --git a/apps/worker/lib/countUnprocessedBillableLinks.ts b/apps/worker/lib/countUnprocessedBillableLinks.tsnew file mode 100644index 00000000..638ae00a--- /dev/null+++ b/apps/worker/lib/countUnprocessedBillableLinks.ts@@ -0,0 +1,29 @@+import { prisma } from "@linkwarden/prisma";++export async function countUnprocessedBillableLinks() {+ const billedOwnerIds = process.env.STRIPE_SECRET_KEY+ ? (+ await prisma.user.findMany({+ where: {+ OR: [+ { subscriptions: { is: { active: true } } },+ { parentSubscription: { is: { active: true } } },+ ],+ },+ select: { id: true },+ })+ ).map((u) => u.id)+ : undefined;++ const count = await prisma.link.count({+ where: {+ lastPreserved: null,+ NOT: { url: null },+ ...(billedOwnerIds && billedOwnerIds.length+ ? { collection: { ownerId: { in: billedOwnerIds } } }+ : {}),+ },+ });++ return count;+}diff --git a/apps/worker/workers/linkProcessing.ts b/apps/worker/workers/linkProcessing.tsindex b6e5eea4..67e941e0 100644--- a/apps/worker/workers/linkProcessing.ts+++ b/apps/worker/workers/linkProcessing.ts@@ -4,6 +4,7 @@ import { LinkWithCollectionOwnerAndTags } from "@linkwarden/types";import { delay } from "@linkwarden/lib";import getLinkBatchFairly from "../lib/getLinkBatchFairly";import { launchBrowser } from "../lib/browser";+import { countUnprocessedBillableLinks } from "../lib/countUnprocessedBillableLinks";const ARCHIVE_TAKE_COUNT = Number(process.env.ARCHIVE_TAKE_COUNT || "") || 5;const BROWSER_MAX_AGE_MS = 30 * 60 * 1000; // 30 minutes@@ -70,9 +71,7 @@ export async function linkProcessing(interval = 10) {const processingPromises = links.map((e) => archiveLink(e));await Promise.allSettled(processingPromises);- const unprocessedLinkCount = await prisma.link.count({- where: { lastPreserved: null, url: { not: null } },- });+ const unprocessedLinkCount = await countUnprocessedBillableLinks();console.log("\x1b[34m%s\x1b[0m",