another firebase fix?

This commit is contained in:
reanon
2025-07-20 04:03:11 +02:00
parent 1f9af4374d
commit 6e02db4bd7
+12 -2
View File
@@ -238,13 +238,23 @@ export function upsertUser(user: UserUpdate) {
if (updates.tokenCounts) {
for (const family of MODEL_FAMILIES) {
updates.tokenCounts[family] ??= { input: 0, output: 0 };
// Preserve existing legacy_total when creating default token counts
const existingCounts = existing.tokenCounts[family];
const defaultCounts: { input: number; output: number; legacy_total?: number } = { input: 0, output: 0 };
if (existingCounts?.legacy_total !== undefined) {
defaultCounts.legacy_total = existingCounts.legacy_total;
}
updates.tokenCounts[family] ??= defaultCounts;
// The property is now guaranteed to be an object, so the 'number' check is removed.
// Defaulting individual fields if they are missing.
const counts = updates.tokenCounts[family]!; // Should not be undefined here
counts.input ??= 0;
counts.output ??= 0;
// legacy_total is optional and not defaulted here if missing
// Preserve legacy_total from existing data if not already set in updates
if (counts.legacy_total === undefined && existingCounts?.legacy_total !== undefined) {
counts.legacy_total = existingCounts.legacy_total;
}
}
}
if (updates.tokenLimits) {