⚡️⚡️⚡️ 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
add hasUnIndexedLinks fields to dashboard data
daniel31x13209e0faa1b7f
diff --git a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.tsindex 1e897855..d289b32d 100644--- a/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts+++ b/apps/web/lib/api/controllers/dashboard/getDashboardDataV2.ts@@ -1,24 +1,42 @@import { prisma } from "@linkwarden/prisma";import { Order } from "@linkwarden/types";+import { MEILI_INDEX_VERSION } from "@linkwarden/lib/constants";export default async function getDashboardData(userId: number) {const order: Order = { id: "desc" };- const [dashboardSections, numberOfPinnedLinks] = await Promise.all([- prisma.dashboardSection.findMany({ where: { userId } }),- prisma.link.count({- where: {- AND: [- {- collection: {- OR: [{ ownerId: userId }, { members: { some: { userId } } }],+ const [dashboardSections, numberOfPinnedLinks, hasUnIndexedLinks] =+ await Promise.all([+ prisma.dashboardSection.findMany({ where: { userId } }),+ prisma.link.count({+ where: {+ AND: [+ {+ collection: {+ OR: [{ ownerId: userId }, { members: { some: { userId } } }],+ },},- },- { pinnedBy: { some: { id: userId } } },- ],- },- }),- ]);+ { pinnedBy: { some: { id: userId } } },+ ],+ },+ }),+ prisma.link.findFirst({+ where: {+ AND: [+ {+ collection: {+ OR: [{ ownerId: userId }, { members: { some: { userId } } }],+ },+ },+ {+ NOT: {+ indexVersion: MEILI_INDEX_VERSION,+ },+ },+ ],+ },+ }),+ ]);const viewPinned = dashboardSections.some((section) => section.type === "PINNED_LINKS"@@ -32,7 +50,7 @@ export default async function getDashboardData(userId: number) {if (!viewRecent && !viewPinned && collectionSections.length === 0) {return {- data: { links: [], numberOfPinnedLinks },+ data: { links: [], numberOfPinnedLinks, hasUnIndexedLinks },message: "Dashboard data fetched successfully.",statusCode: 200,success: true,@@ -143,6 +161,7 @@ export default async function getDashboardData(userId: number) {links: uniqueLinks,collectionLinks,numberOfPinnedLinks,+ hasUnIndexedLinks,},message: "Dashboard data fetched successfully.",statusCode: 200,diff --git a/apps/web/lib/api/controllers/worker/getWorkerStats.ts b/apps/web/lib/api/controllers/worker/getWorkerStats.tsindex 5ebf0672..634b2359 100644--- a/apps/web/lib/api/controllers/worker/getWorkerStats.ts+++ b/apps/web/lib/api/controllers/worker/getWorkerStats.ts@@ -1,3 +1,4 @@+import { MEILI_INDEX_VERSION } from "@linkwarden/lib/constants";import { prisma } from "@linkwarden/prisma";import { WorkerStats } from "@linkwarden/types";@@ -32,17 +33,18 @@ export default async function getWorkerStats(userId: number) {},});- const INDEX_VERSION = 1;-const searchPending = await prisma.link.count({where: {- OR: [{ indexVersion: { not: INDEX_VERSION } }, { indexVersion: null }],+ OR: [+ { indexVersion: { not: MEILI_INDEX_VERSION } },+ { indexVersion: null },+ ],},});const searchDone = await prisma.link.count({where: {- indexVersion: INDEX_VERSION,+ indexVersion: MEILI_INDEX_VERSION,},});diff --git a/apps/worker/workers/linkIndexing.ts b/apps/worker/workers/linkIndexing.tsindex fc533ef4..d3b9e10b 100644--- a/apps/worker/workers/linkIndexing.ts+++ b/apps/worker/workers/linkIndexing.ts@@ -1,6 +1,7 @@import { delay, meiliClient } from "@linkwarden/lib";import { prisma } from "@linkwarden/prisma";import getLinkBatch from "../lib/getLinkBatch";+import { MEILI_INDEX_VERSION } from "@linkwarden/lib/constants";const takeCount = Number(process.env.INDEX_TAKE_COUNT || "") || 50;@@ -65,7 +66,6 @@ export async function startIndexing(interval = 10) {console.log("\x1b[34m%s\x1b[0m", "Starting link indexing...");- const INDEX_VERSION = 1;const TRIAL_PERIOD_DAYS = process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS || 14;const REQUIRE_CC = process.env.NEXT_PUBLIC_REQUIRE_CC === "true";@@ -75,7 +75,7 @@ export async function startIndexing(interval = 10) {AND: [{OR: [- { indexVersion: { not: INDEX_VERSION } },+ { indexVersion: { not: MEILI_INDEX_VERSION } },{ indexVersion: null },],},@@ -146,7 +146,7 @@ export async function startIndexing(interval = 10) {tags: link.tags.map((t) => t.name),pinnedBy: link.pinnedBy.map((p) => p.id),creationTimestamp: Date.parse(link.createdAt.toISOString()) / 1000,- indexVersion: INDEX_VERSION,+ indexVersion: MEILI_INDEX_VERSION,}));const task = await meiliClient.index("links").addDocuments(docs);@@ -162,12 +162,15 @@ export async function startIndexing(interval = 10) {const ids = links.map((l) => l.id);await prisma.link.updateMany({where: { id: { in: ids } },- data: { indexVersion: INDEX_VERSION },+ data: { indexVersion: MEILI_INDEX_VERSION },});const indexesLeft = await prisma.link.count({where: {- OR: [{ indexVersion: { not: INDEX_VERSION } }, { indexVersion: null }],+ OR: [+ { indexVersion: { not: MEILI_INDEX_VERSION } },+ { indexVersion: null },+ ],lastPreserved: { not: null },},});diff --git a/packages/lib/constants.ts b/packages/lib/constants.tsnew file mode 100644index 00000000..4c64abe5--- /dev/null+++ b/packages/lib/constants.ts@@ -0,0 +1 @@+export const MEILI_INDEX_VERSION = 1;