Skip to content

Commit 5b1f004

Browse files
committed
fix: update overview query to order by descending date and reverse daily data
1 parent 3683565 commit 5b1f004

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

lib/queries/overview.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { and, eq, sql, gte, lte } from "drizzle-orm";
1+
import { and, eq, sql, gte, lte, desc } from "drizzle-orm";
22
import type { SQL } from "drizzle-orm";
33
import { db } from "@/lib/db/client";
44
import { modelPrices, usageRecords } from "@/lib/db/schema";
@@ -156,7 +156,7 @@ export async function getOverview(
156156
.from(usageRecords)
157157
.where(filterWhere)
158158
.groupBy(dayExpr)
159-
.orderBy(dayExpr)
159+
.orderBy(desc(dayExpr))
160160
.limit(days);
161161

162162
const byDayModelPromise: Promise<DayModelAggRow[]> = db
@@ -274,7 +274,7 @@ export async function getOverview(
274274
dailyCostMap.set(row.label, (dailyCostMap.get(row.label) ?? 0) + cost);
275275
}
276276

277-
const byDay: UsageSeriesPoint[] = byDayRows.map((row) => ({
277+
const byDay: UsageSeriesPoint[] = [...byDayRows].reverse().map((row) => ({
278278
label: row.label,
279279
requests: toNumber(row.requests),
280280
tokens: toNumber(row.tokens),

0 commit comments

Comments
 (0)