Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ export function UsageLogsFilters({
return dynamicOnly;
}, [dynamicStatusCodes]);

const userMap = useMemo(() => new Map(users.map((user) => [user.id, user.name])), [users]);

const providerMap = useMemo(
() => new Map(providers.map((provider) => [provider.id, provider.name])),
[providers]
);

const [keys, setKeys] = useState<Key[]>(initialKeys);
const [localFilters, setLocalFilters] = useState(filters);
const [isExporting, setIsExporting] = useState(false);
Expand Down Expand Up @@ -285,8 +292,7 @@ export function UsageLogsFilters({
className="w-full justify-between"
>
{localFilters.userId ? (
(users.find((user) => user.id === localFilters.userId)?.name ??
localFilters.userId.toString())
(userMap.get(localFilters.userId) ?? localFilters.userId.toString())
) : (
<span className="text-muted-foreground">
{isUsersLoading ? t("logs.stats.loading") : t("logs.filters.allUsers")}
Expand Down Expand Up @@ -392,8 +398,7 @@ export function UsageLogsFilters({
className="w-full justify-between"
>
{localFilters.providerId ? (
(providers.find((provider) => provider.id === localFilters.providerId)?.name ??
localFilters.providerId.toString())
(providerMap.get(localFilters.providerId) ?? localFilters.providerId.toString())
) : (
<span className="text-muted-foreground">
{isProvidersLoading
Expand Down
2 changes: 1 addition & 1 deletion src/repository/usage-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export async function findUsageLogsBatch(
.select({
id: messageRequest.id,
createdAt: messageRequest.createdAt,
createdAtRaw: sql<string>`to_char(${messageRequest.createdAt}, 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"')`,
createdAtRaw: sql<string>`to_char(${messageRequest.createdAt} AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"')`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and avoid magic strings, consider extracting the timestamp format YYYY-MM-DD"T"HH24:MI:SS.US"Z" into a shared constant. This same format string is also used in src/repository/user.ts. A shared constant would ensure consistency and make future updates easier.

sessionId: messageRequest.sessionId,
requestSequence: messageRequest.requestSequence,
userName: users.name,
Expand Down
2 changes: 1 addition & 1 deletion src/repository/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export async function findUserListBatch(
providerGroup: users.providerGroup,
tags: users.tags,
createdAt: users.createdAt,
createdAtRaw: sql<string>`to_char(${users.createdAt}, 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"')`,
createdAtRaw: sql<string>`to_char(${users.createdAt} AT TIME ZONE 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.US"Z"')`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This timestamp format string YYYY-MM-DD"T"HH24:MI:SS.US"Z" is also used in src/repository/usage-logs.ts. To avoid duplication and improve maintainability, it would be best to define this as a shared constant in a single location and reference it from both files.

updatedAt: users.updatedAt,
deletedAt: users.deletedAt,
limit5hUsd: users.limit5hUsd,
Expand Down
Loading