From e092280718073013510b85168b9e2cf3b6d4b230 Mon Sep 17 00:00:00 2001 From: SeaXen <71036788+SeaXen@users.noreply.github.com> Date: Sun, 19 Jul 2026 06:18:18 +0600 Subject: [PATCH] fix(usage): reset logs and show provider names in analytics (#7264) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(usage): reset logs and show provider names in analytics * refactor(db): extract usage purge routines to cleanup module (file-size cap) Move the generic delete-all/delete-before-cutoff table helpers and the call-log-artifact purge helpers out of cleanup.ts into a new cleanup/usagePurge.ts submodule, so this PR's growth in cleanup.ts stays under the file-size gate cap once combined with other in-flight changes to the same file. Pure extraction — resetUsageHistory delegates to the same logic, now imported instead of inlined; no behavior change. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * refactor(db): hoist reset targets table + derive total via reduce (max-lines-per-function) Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * refactor(api): move analytics provider-name enrichment into lib (file-size cap) src/app/api/usage/analytics/route.ts is a frozen file-size-capped file (baseline: 942 lines, zero headroom on this branch). The provider display-name enrichment added for the byProvider breakdown (id -> name/ prefix lookup via provider_nodes) pushed it to 971 lines, tripping the check:file-size ratchet. Move the new getProviderDisplayName/getProviderDisplayNames helpers, plus the byProvider row-building they modified, into a new leaf module src/lib/usage/providerDisplayNames.ts (buildByProviderRows). The route now just imports and calls it. No behavior change: same lookup, same fallback to the raw provider id, same row shape. Net effect: route.ts drops from 941 (pre-change) to 930 lines (-11), comfortably restoring headroom instead of exceeding the frozen cap. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * fix(usage): fall back to static catalog name in provider display resolution Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --- .../settings/components/SystemStorageTab.tsx | 2 +- .../api/settings/purge-usage-history/route.ts | 10 ++ src/app/api/usage/analytics/route.ts | 15 +-- src/i18n/messages/en.json | 2 +- src/lib/db/cleanup.ts | 100 +++++++++----- src/lib/db/cleanup/usagePurge.ts | 83 ++++++++++++ src/lib/usage/providerDisplayNames.ts | 88 +++++++++++++ tests/unit/usage-history-reset.test.ts | 124 +++++++++++++++++- 8 files changed, 373 insertions(+), 51 deletions(-) create mode 100644 src/lib/db/cleanup/usagePurge.ts create mode 100644 src/lib/usage/providerDisplayNames.ts diff --git a/src/app/(dashboard)/dashboard/settings/components/SystemStorageTab.tsx b/src/app/(dashboard)/dashboard/settings/components/SystemStorageTab.tsx index 7f4b57aeac..e7a382026d 100644 --- a/src/app/(dashboard)/dashboard/settings/components/SystemStorageTab.tsx +++ b/src/app/(dashboard)/dashboard/settings/components/SystemStorageTab.tsx @@ -1541,7 +1541,7 @@ export default function SystemStorageTab() {

{t("resetUsageDataDesc") || - "Select how far back you want to delete usage data. This action cannot be undone."} + "Select how far back you want to delete usage, request logs, and analytics data. Provider configuration, connections, API keys, combos, and settings are preserved. This action cannot be undone."}