Skip to content

Commit ba550e1

Browse files
committed
Safety limits for pagination and prettier icons
1 parent ea9984d commit ba550e1

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

components/dashboard/src/Insights.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export const DownloadUsage = ({ from, to }: DownloadUsageProps) => {
205205

206206
return (
207207
<Button variant="secondary" onClick={handleDownload} className="gap-1" disabled={downloadDisabled}>
208-
<DownloadIcon />
208+
<DownloadIcon strokeWidth={3} className="w-4" />
209209
<span>Export as CSV</span>
210210
</Button>
211211
);

components/dashboard/src/insights/download/download-sessions.ts

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import { useCallback } from "react";
1616
import { noPersistence } from "../../data/setup";
1717
import { Timestamp } from "@bufbuild/protobuf";
1818

19+
const pageSize = 100;
20+
const maxPages = 100; // safety limit if something goes wrong with pagination
21+
1922
type GetAllWorkspaceSessionsArgs = Pick<ListWorkspaceSessionsRequest, "to" | "from" | "organizationId"> & {
2023
signal?: AbortSignal;
2124
onProgress?: (percentage: number) => void;
@@ -27,24 +30,23 @@ export const getAllWorkspaceSessions = async ({
2730
organizationId,
2831
onProgress,
2932
}: GetAllWorkspaceSessionsArgs): Promise<WorkspaceSession[]> => {
30-
let page = 0;
3133
const records: WorkspaceSession[] = [];
32-
33-
while (true) {
34-
if (signal?.aborted === true) {
35-
return [];
36-
}
37-
38-
const response = await workspaceClient.listWorkspaceSessions({
39-
organizationId,
40-
from,
41-
to,
42-
pagination: {
43-
page,
44-
pageSize: 100,
34+
let page = 0;
35+
while (!signal?.aborted && page < maxPages) {
36+
const response = await workspaceClient.listWorkspaceSessions(
37+
{
38+
organizationId,
39+
from,
40+
to,
41+
pagination: {
42+
page,
43+
pageSize,
44+
},
45+
},
46+
{
47+
signal,
4548
},
46-
});
47-
console.log(response.workspaceSessions.length);
49+
);
4850
if (response.workspaceSessions.length === 0) {
4951
break;
5052
}
@@ -106,6 +108,11 @@ const downloadUsageCSV = async ({
106108
const csvRows = rows.map((row) => {
107109
const rowString = fields
108110
.map((fieldName) => {
111+
const value = row[fieldName];
112+
if (typeof value === "bigint") {
113+
return value.toString();
114+
}
115+
109116
return JSON.stringify(row[fieldName]);
110117
})
111118
.join(",");
@@ -171,6 +178,10 @@ export const transformSessionRecord = (session: WorkspaceSession) => {
171178
contextURL: session.workspace?.metadata?.originalContextUrl,
172179
workspaceType: displayWorkspaceType(session.workspace?.spec?.type),
173180
workspaceClass: session.workspace?.spec?.class,
181+
182+
workspaceImageSize: session.metrics?.workspaceImageSize,
183+
workspaceImageTotalSize: session.metrics?.totalImageSize,
184+
ide: session.workspace?.spec?.editor?.name, // maybe?
174185
};
175186

176187
return row;

0 commit comments

Comments
 (0)