import { BaseSchema } from '@adonisjs/lucid/schema' /** * The prefetcher's ranges every 2 s (REBUILD.md, prefetch): the leased ones * and the planned ones it started spooling. Without these it read all * ranges each time (~15–25 ms with 145k planned; LOG.md 2026-10-09). */ export default class extends BaseSchema { async up() { this.schema.raw(`CREATE INDEX IF NOT EXISTS ranges_leased_idx ON ranges (leased_at) WHERE status = 'leased'`) this.schema.raw(`CREATE INDEX IF NOT EXISTS ranges_spooling_idx ON ranges (priority, id) WHERE status = 'planned' AND spooled_chunks > 0`) } async down() { this.schema.raw(`DROP INDEX IF EXISTS ranges_spooling_idx`) this.schema.raw(`DROP INDEX IF EXISTS ranges_leased_idx`) } }