Skip to content

Commit a84d060

Browse files
committed
🤖 Remove unused stats.calculate IPC method
The stats.calculate endpoint is no longer used. Commit 221e81e moved consumer calculation to the frontend using pure functions (consumerCalculator.ts) with backend tokenization via tokens.countBulk. Removed: - STATS_CALCULATE IPC handler (~20 lines) - STATS_CALCULATE constant - stats.calculate from preload API - stats interface from IPCApi type - statsCalculate.test.ts (125 lines testing dead code) Impact: - Simpler IPC surface (one tokenization endpoint vs two) - -150 LoC removed - All 528 tests still pass - No functionality lost (calculation moved to frontend)
1 parent d1bc384 commit a84d060

File tree

5 files changed

+0
-170
lines changed

5 files changed

+0
-170
lines changed

src/constants/ipc-constants.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ export const IPC_CHANNELS = {
3838
// Window channels
3939
WINDOW_SET_TITLE: "window:setTitle",
4040

41-
// Stats channels
42-
STATS_CALCULATE: "stats:calculate",
43-
4441
// Token channels
4542
TOKENS_COUNT_BULK: "tokens:countBulk",
4643

src/preload.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ const api: IPCApi = {
110110
window: {
111111
setTitle: (title: string) => ipcRenderer.invoke(IPC_CHANNELS.WINDOW_SET_TITLE, title),
112112
},
113-
stats: {
114-
calculate: (workspaceId: string, model: string) =>
115-
ipcRenderer.invoke(IPC_CHANNELS.STATS_CALCULATE, workspaceId, model),
116-
},
117113
tokens: {
118114
countBulk: (model: string, texts: string[]) =>
119115
ipcRenderer.invoke(IPC_CHANNELS.TOKENS_COUNT_BULK, model, texts),

src/services/ipcMain.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ export class IpcMain {
159159

160160
this.registerDialogHandlers(ipcMain);
161161
this.registerWindowHandlers(ipcMain);
162-
this.registerStatsHandlers(ipcMain);
163162
this.registerTokenHandlers(ipcMain);
164163
this.registerWorkspaceHandlers(ipcMain);
165164
this.registerProviderHandlers(ipcMain);
@@ -195,29 +194,7 @@ export class IpcMain {
195194
});
196195
}
197196

198-
private registerStatsHandlers(ipcMain: ElectronIpcMain): void {
199-
ipcMain.handle(
200-
IPC_CHANNELS.STATS_CALCULATE,
201-
async (_event, workspaceId: string, model: string) => {
202-
try {
203-
const historyResult = await this.historyService.getHistory(workspaceId);
204-
if (!historyResult.success) {
205-
return null;
206-
}
207197

208-
// Dynamic import to lazy-load tokenizer (prevents ~3-4s startup freeze)
209-
// The tokenizer module is large (~2MB) and only needed when viewing costs tab
210-
/* eslint-disable no-restricted-syntax */
211-
const { calculateTokenStats } = await import("@/utils/tokens/tokenStatsCalculator");
212-
/* eslint-enable no-restricted-syntax */
213-
return calculateTokenStats(historyResult.data, model);
214-
} catch (error) {
215-
log.error(`Failed to calculate stats for workspace ${workspaceId}:`, error);
216-
return null;
217-
}
218-
}
219-
);
220-
}
221198

222199
private registerTokenHandlers(ipcMain: ElectronIpcMain): void {
223200
ipcMain.handle(

src/types/ipc.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,6 @@ export interface IPCApi {
231231
window: {
232232
setTitle(title: string): Promise<void>;
233233
};
234-
stats: {
235-
calculate(workspaceId: string, model: string): Promise<ChatStats | null>;
236-
};
237234
tokens: {
238235
countBulk(model: string, texts: string[]): Promise<number[] | null>;
239236
};

tests/ipcMain/statsCalculate.test.ts

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)