This commit is contained in:
daniel31x13
2025-09-01 20:17:11 -04:00
parent 8526442782
commit cb1f42e0a2
2 changed files with 31 additions and 3 deletions

View File

@@ -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;
}

View File

@@ -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",