Bound habit day and calendar reads to requested history
This commit is contained in:
23
src/habits/performance.test.ts
Normal file
23
src/habits/performance.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { expect, test } from 'bun:test';
|
||||
import { fixture } from './test-fixture';
|
||||
import { HabitService } from './service';
|
||||
import { publicUser } from '../auth';
|
||||
import { users } from '../db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
test('single-day reads load only the selected latest snapshot and its tasks', async () => {
|
||||
const f = fixture();
|
||||
try {
|
||||
const habit = await f.json('/habits', 'POST', { name: 'Tasks', method: 'tasks', tasks: [{name:'Read'}] }, 201);
|
||||
f.setTime('2027-09-04T12:00:00Z');
|
||||
await f.json('/today');
|
||||
const logs: string[] = [];
|
||||
(f.db as any).session.logger = { logQuery(query: string) { logs.push(query); } };
|
||||
const service = new HabitService(f.db, publicUser(f.db.select().from(users).where(eq(users.id,'alice')).get()!), Date.parse('2027-09-04T12:00:00Z'));
|
||||
const day = service.day(habit.id, '2027-09-04');
|
||||
expect(day.tasks).toHaveLength(1);
|
||||
expect((service as any).recordsCache.get(habit.id).size).toBe(1);
|
||||
expect((service as any).occurrencesCache.get(habit.id).size).toBe(1);
|
||||
expect(logs.find(query => query.includes('task_occurrences'))).toContain('"habit_days"."date" >=');
|
||||
} finally { f.close(); }
|
||||
});
|
||||
Reference in New Issue
Block a user