mirror of
https://github.com/linkwarden/linkwarden.git
synced 2026-03-03 03:47:02 +00:00
bug fix
This commit is contained in:
29
apps/worker/lib/countUnprocessedBillableLinks.ts
Normal file
29
apps/worker/lib/countUnprocessedBillableLinks.ts
Normal 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;
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user