perf(team): avoid redundant task cache clone
This commit is contained in:
parent
7be9158eb3
commit
304d0a5ef1
2 changed files with 19 additions and 1 deletions
|
|
@ -600,7 +600,7 @@ export class TeamTaskReader {
|
||||||
const tasks = await request;
|
const tasks = await request;
|
||||||
if (TeamTaskReader.allTasksGeneration === generationAtStart) {
|
if (TeamTaskReader.allTasksGeneration === generationAtStart) {
|
||||||
TeamTaskReader.allTasksCache = {
|
TeamTaskReader.allTasksCache = {
|
||||||
value: cloneTasks(tasks),
|
value: tasks,
|
||||||
expiresAt: Date.now() + ALL_TASKS_CACHE_TTL_MS,
|
expiresAt: Date.now() + ALL_TASKS_CACHE_TTL_MS,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,24 @@ describe('TeamTaskReader', () => {
|
||||||
expect(readAllTasksUncached).toHaveBeenCalledTimes(2);
|
expect(readAllTasksUncached).toHaveBeenCalledTimes(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keeps cached getAllTasks data isolated from caller mutations', async () => {
|
||||||
|
const readAllTasksUncached = vi
|
||||||
|
.spyOn(
|
||||||
|
TeamTaskReader.prototype as unknown as {
|
||||||
|
readAllTasksUncached: () => Promise<(TeamTask & { teamName: string })[]>;
|
||||||
|
},
|
||||||
|
'readAllTasksUncached'
|
||||||
|
)
|
||||||
|
.mockResolvedValueOnce([makeTask('cached-task')]);
|
||||||
|
|
||||||
|
const reader = new TeamTaskReader();
|
||||||
|
const firstRead = await reader.getAllTasks();
|
||||||
|
firstRead[0]!.subject = 'mutated caller copy';
|
||||||
|
|
||||||
|
await expect(reader.getAllTasks()).resolves.toEqual([makeTask('cached-task')]);
|
||||||
|
expect(readAllTasksUncached).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
it('reuses parsed task files until their file signature changes', async () => {
|
it('reuses parsed task files until their file signature changes', async () => {
|
||||||
await setupTasksRoot();
|
await setupTasksRoot();
|
||||||
await writeTaskFile('atlas-hq', {
|
await writeTaskFile('atlas-hq', {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue