feat(defects): read API — feed, per-section counts and history (T6)
GET /api/defects returns a newest-first feed joined to the project name,
bounded by limit; ?section=ID narrows to one section's history. GET
/api/defects/counts returns { sectionId: n } for the weak-point map. Adds a
(section_id, created_at) index and a db:seed script; ~2k rows query in ~20ms.
This commit is contained in:
23
server/db/seed.ts
Normal file
23
server/db/seed.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// Seed defects for perf-checking the dashboard (F6 target: ≤1s at ~2k rows).
|
||||
// SEED_COUNT=2000 pnpm db:seed
|
||||
import { getDb, getPool } from './client'
|
||||
import { createProject } from './repositories/projects'
|
||||
import { defects } from './schema'
|
||||
import { sections } from '../../app/board/definition'
|
||||
|
||||
const count = Number(process.env.SEED_COUNT ?? 2000)
|
||||
const db = getDb()
|
||||
|
||||
const project = await createProject(db, 'Seed Project')
|
||||
const rows = Array.from({ length: count }, (_, i) => ({
|
||||
sectionId: sections[i % sections.length]!.id,
|
||||
projectId: project.id,
|
||||
verbatim: `seeded defect #${i}`,
|
||||
reporterEmail: 'seed@theodo.com',
|
||||
// Spread timestamps so the feed ordering is meaningful.
|
||||
createdAt: new Date(Date.now() - i * 60_000),
|
||||
}))
|
||||
|
||||
await db.insert(defects).values(rows)
|
||||
console.log(`[seed] inserted ${count} defects`)
|
||||
await getPool().end()
|
||||
Reference in New Issue
Block a user