From de0972345454e3211c408c1842e5ec1f90c63dd6 Mon Sep 17 00:00:00 2001 From: MarkLo127 Date: Wed, 11 Mar 2026 16:56:32 +0800 Subject: [PATCH] --- frontend/Dockerfile.railway | 6 +++--- frontend/app/history/page.tsx | 27 ++++++++++++++++++++++++++- test-duplicate-records.js | 2 ++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 test-duplicate-records.js diff --git a/frontend/Dockerfile.railway b/frontend/Dockerfile.railway index 09765649..1912fc00 100644 --- a/frontend/Dockerfile.railway +++ b/frontend/Dockerfile.railway @@ -17,9 +17,9 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY frontend . -# Accept BACKEND_URL as build argument -ARG BACKEND_URL -ENV BACKEND_URL=${BACKEND_URL} +# Accept NEXT_PUBLIC_API_URL as build argument +ARG NEXT_PUBLIC_API_URL +ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} # Build Next.js app RUN bun run build diff --git a/frontend/app/history/page.tsx b/frontend/app/history/page.tsx index 4c2f37e1..20eaa756 100644 --- a/frontend/app/history/page.tsx +++ b/frontend/app/history/page.tsx @@ -41,6 +41,8 @@ import { getReportsByMarketType, deleteReport, getReportCountByMarketType, + deleteReports, + getAllReports, type SavedReport, } from "@/lib/reports-db"; import { @@ -440,7 +442,30 @@ export default function HistoryPage() { hasAutoSyncedRef.current = true; try { - // Get all local reports + // First auto-clean local duplicates that might exist from older flawed versions + try { + const allLocal = await getAllReports(); + const seenSignatures = new Set(); + const idsToDelete: number[] = []; + + for (const report of allLocal) { + const signature = getReportSignature(report as any); + if (seenSignatures.has(signature)) { + if (report.id) idsToDelete.push(report.id); + } else { + seenSignatures.add(signature); + } + } + + if (idsToDelete.length > 0) { + console.log(`🧹 Found ${idsToDelete.length} duplicate local reports from flawed storage, cleaning them up...`); + await deleteReports(idsToDelete); + } + } catch (err) { + console.error("Failed to cleanup local duplicates:", err); + } + + // Get all local reports (re-fetch after cleanup) const [usLocal, twseLocal, tpexLocal] = await Promise.all([ getReportsByMarketType("us"), getReportsByMarketType("twse"), diff --git a/test-duplicate-records.js b/test-duplicate-records.js new file mode 100644 index 00000000..29e001b1 --- /dev/null +++ b/test-duplicate-records.js @@ -0,0 +1,2 @@ +// Script to clear IndexedDB duplicate records from user's Chrome +console.log('To clear duplicate reports, the user needs to clear IndexedDB or we can add a cleanup script to the app.');