Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/repository/leaderboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ async function findLeaderboardWithTimezone(
.innerJoin(users, and(sql`${usageLedger.userId} = ${users.id}`, isNull(users.deletedAt)))
.where(and(...whereConditions))
.groupBy(usageLedger.userId, users.name)
.orderBy(desc(sql`sum(${usageLedger.costUsd})`));
.orderBy(desc(sql`COALESCE(sum(${usageLedger.costUsd}), 0)`));
Comment thread
hank9999 marked this conversation as resolved.

const baseEntries: LeaderboardEntry[] = rankings.map((entry) => ({
userId: entry.userId,
Expand Down Expand Up @@ -404,7 +404,7 @@ async function findLeaderboardWithTimezone(
.innerJoin(users, and(sql`${usageLedger.userId} = ${users.id}`, isNull(users.deletedAt)))
.where(and(...whereConditions))
.groupBy(usageLedger.userId, modelField)
.orderBy(desc(sql`sum(${usageLedger.costUsd})`));
.orderBy(desc(sql`COALESCE(sum(${usageLedger.costUsd}), 0)`));
Comment thread
hank9999 marked this conversation as resolved.

const modelStatsByUser = new Map<number, UserModelStat[]>();
for (const row of modelRows) {
Expand Down Expand Up @@ -696,7 +696,7 @@ async function findProviderLeaderboardWithTimezone(
and(...whereConditions.filter((c): c is NonNullable<(typeof whereConditions)[number]> => !!c))
)
.groupBy(usageLedger.finalProviderId, providers.name)
.orderBy(desc(sql`sum(${usageLedger.costUsd})`));
.orderBy(desc(sql`COALESCE(sum(${usageLedger.costUsd}), 0)`));
Comment thread
hank9999 marked this conversation as resolved.

const baseEntries: ProviderLeaderboardEntry[] = rankings.map((entry) => {
const totalCost = parseFloat(entry.totalCost);
Expand Down Expand Up @@ -747,7 +747,7 @@ async function findProviderLeaderboardWithTimezone(
and(...whereConditions.filter((c): c is NonNullable<(typeof whereConditions)[number]> => !!c))
)
.groupBy(usageLedger.finalProviderId, modelField)
.orderBy(desc(sql`sum(${usageLedger.costUsd})`), desc(sql`count(*)`));
.orderBy(desc(sql`COALESCE(sum(${usageLedger.costUsd}), 0)`), desc(sql`count(*)`));
Comment thread
hank9999 marked this conversation as resolved.

const modelStatsByProvider = new Map<number, ModelProviderStat[]>();
for (const row of modelRows) {
Expand Down Expand Up @@ -1153,7 +1153,7 @@ async function findModelLeaderboardWithTimezone(
.from(usageLedger)
.where(and(LEDGER_BILLING_CONDITION, buildDateCondition(period, timezone, dateRange)))
.groupBy(modelField)
.orderBy(desc(sql`sum(${usageLedger.costUsd})`), desc(sql`count(*)`));
.orderBy(desc(sql`COALESCE(sum(${usageLedger.costUsd}), 0)`), desc(sql`count(*)`));
Comment thread
hank9999 marked this conversation as resolved.
Comment thread
hank9999 marked this conversation as resolved.

return rankings
.filter((entry) => entry.model !== null && entry.model !== "")
Expand Down
Loading