📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Fix incorrect revenue trends chart
Blue Mouse6fa53ea9ecf8
diff --git a/backend/apps/cloud/src/admin/admin.service.ts b/backend/apps/cloud/src/admin/admin.service.tsindex 431035677..bd0b43970 100644--- a/backend/apps/cloud/src/admin/admin.service.ts+++ b/backend/apps/cloud/src/admin/admin.service.ts@@ -204,7 +204,9 @@ const REVENUE_CACHE_KEY = 'admin:paddle-payments:v2'const REVENUE_CACHE_TTL_SECONDS = 3600const PADDLE_FETCH_TIMEOUT_MS = 15000-const REVENUE_HISTORY_CACHE_KEY = 'admin:paddle-payments-history:v1'+// v2: v1 was fetched with inclusive-looking chunk ends and is missing every+// boundary-day payment - never serve it again+const REVENUE_HISTORY_CACHE_KEY = 'admin:paddle-payments-history:v2'// History only changes when a new payment lands, and the trends are a// month-level view - a stale-by-hours cache is fineconst REVENUE_HISTORY_CACHE_TTL_SECONDS = 6 * 60 * 60@@ -549,6 +551,9 @@ export class AdminService {const previousMonthStart = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - 1, 1),)+ // Paddle's `to` is exclusive, so the paid range must end tomorrow for+ // today's payments to be included+ const tomorrow = new Date(now.getTime() + 24 * 60 * 60 * 1000)const upcomingUntil = new Date(now.getTime() + 45 * 24 * 60 * 60 * 1000)let result@@ -557,7 +562,7 @@ export class AdminService {const [paid, upcoming] = await Promise.all([this.fetchPaddlePayments(toDateString(previousMonthStart),- toDateString(now),+ toDateString(tomorrow),1,),this.fetchPaddlePayments(@@ -665,17 +670,19 @@ export class AdminService {),)) {- // Day 0 of the month after the chunk = last day of the chunk, so the- // ranges never overlap- const chunkEnd = new Date(+ // Paddle's `to` is EXCLUSIVE (verified against the live API: payments+ // whose payout_date equals `to` are not returned), so each chunk must+ // end on the first day of the next one - ending on the chunk's own last+ // day silently drops every payment landing exactly on that day+ const nextChunkStart = new Date(Date.UTC(cursor.getUTCFullYear(),cursor.getUTCMonth() + REVENUE_HISTORY_CHUNK_MONTHS,- 0,+ 1,),)- ranges.push([toDateString(cursor), toDateString(chunkEnd)])+ ranges.push([toDateString(cursor), toDateString(nextChunkStart)])}const seenIds = new Set<number>()diff --git a/web/app/pages/Admin/AdminChart.tsx b/web/app/pages/Admin/AdminChart.tsxindex 267228ea0..c7a625c99 100644--- a/web/app/pages/Admin/AdminChart.tsx+++ b/web/app/pages/Admin/AdminChart.tsx@@ -5,7 +5,7 @@ import dayjs from 'dayjs'import { useMemo } from 'react'import BillboardChart from '~/ui/BillboardChart'-import { nFormatter } from '~/utils/generic'+import { cn, nFormatter } from '~/utils/generic'import type { SeriesPoint } from './types'@@ -179,7 +179,10 @@ export const AdminChart = ({return (<BillboardChartoptions={options}- className={className}+ // admin-chart scopes the ProjectViewStyle.css overrides (solid bars, no+ // stroke) - admin series ids never match the project view's per-target+ // stroke rules, so without it bars render with a black outline+ className={cn('admin-chart', className)}deps={[series, format]}/>)diff --git a/web/app/styles/ProjectViewStyle.css b/web/app/styles/ProjectViewStyle.cssindex e24618e5c..244960476 100644--- a/web/app/styles/ProjectViewStyle.css+++ b/web/app/styles/ProjectViewStyle.css@@ -340,6 +340,15 @@ body.dark .bb-chart-arc path {stroke: var(--color-slate-900);}+/* Admin panel charts: same problem as the AI charts below - series ids+ ('cash', 'recognised', ...) don't match the per-target stroke rules above,+ so bars would render washed out with a stray dark outline. */+.admin-chart .bb-bar {+ fill-opacity: 0.85 !important;+ stroke: none !important;+ stroke-width: 0 !important;+}+/* AI chat charts: keep bars/areas opaque since their series names don't matchthe project view's stroke rules; without this they'd inherit the global.bb-bar { fill-opacity: 0.3 } and look washed out. */