Skip to content

Commit d9eb84b

Browse files
committed
refactor: remove path logic
1 parent a530134 commit d9eb84b

File tree

3 files changed

+7
-40
lines changed

3 files changed

+7
-40
lines changed

packages/utils/src/lib/profiler/wal-json-trace.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ export const traceEventWalFormat = <
9898
JSON.stringify(encodeTraceEvent(event)),
9999
decode: (json: string) => decodeTraceEvent(JSON.parse(json)) as T,
100100
},
101-
shardPath: (id: string) =>
102-
groupId
103-
? `${baseName}.${groupId}.${id}${walExtension}`
104-
: `${baseName}.${id}${walExtension}`,
105-
finalPath: () =>
106-
groupId
107-
? `${baseName}.${groupId}${finalExtension}`
108-
: `${baseName}${finalExtension}`,
109101
finalizer: (
110102
records: (UserTimingTraceEvent | InvalidEntry<string>)[],
111103
metadata?: Record<string, unknown>,

packages/utils/src/lib/profiler/wal-json-trace.unit.test.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ describe('traceEventWalFormat', () => {
223223
baseName: 'trace',
224224
walExtension: '.jsonl',
225225
finalExtension: '.json',
226-
shardPath: expect.any(Function),
227-
finalPath: expect.any(Function),
228226
codec: {
229227
encode: expect.any(Function),
230228
decode: expect.any(Function),
@@ -249,36 +247,6 @@ describe('traceEventWalFormat', () => {
249247
expect(format.finalExtension).toBe('.json');
250248
});
251249

252-
it('should generate correct shard paths', () => {
253-
const format = traceEventWalFormat();
254-
255-
expect(format.shardPath('shard-1')).toBe('trace.shard-1.jsonl');
256-
expect(format.shardPath('process-123-thread-456')).toBe(
257-
'trace.process-123-thread-456.jsonl',
258-
);
259-
});
260-
261-
it('should generate correct shard paths with groupId', () => {
262-
const format = traceEventWalFormat({ groupId: 'session-123' });
263-
264-
expect(format.shardPath('shard-1')).toBe('trace.session-123.shard-1.jsonl');
265-
expect(format.shardPath('process-123-thread-456')).toBe(
266-
'trace.session-123.process-123-thread-456.jsonl',
267-
);
268-
});
269-
270-
it('should generate correct final path', () => {
271-
const format = traceEventWalFormat();
272-
273-
expect(format.finalPath()).toBe('trace.json');
274-
});
275-
276-
it('should generate correct final path with groupId', () => {
277-
const format = traceEventWalFormat({ groupId: 'session-123' });
278-
279-
expect(format.finalPath()).toBe('trace.session-123.json');
280-
});
281-
282250
it('should encode and decode trace events correctly', () => {
283251
const format = traceEventWalFormat();
284252
const testEvent: UserTimingTraceEvent = {

packages/utils/src/lib/wal.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,5 +496,12 @@ export class ShardedWal<T extends object | string = object> {
496496
// Directory might not be empty or already removed, ignore
497497
}
498498
});
499+
500+
// Also try to remove the root directory if it becomes empty
501+
try {
502+
fs.rmdirSync(this.#dir);
503+
} catch {
504+
// Directory might not be empty or already removed, ignore
505+
}
499506
}
500507
}

0 commit comments

Comments
 (0)