Public: anyone can read this; the crew can change it.
Whether reports are closed is read from the database, so every process agrees #15053
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15039-whether-reports-are-closed-is-read-from → main 1 commit fork
2 files
changed +62
−19
src/core/reports.ts +6 −19
| @@ -212,30 +212,17 @@ export function outsideTitle( | ||
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
| 215 | * Which repositories have closed the door, held per database after the first | |
| 216 | * read (every repository page asks): `setReportsClosed` is the only writer, so | |
| 217 | * it keeps the set. At most one id per closed repository, gone on restart. | |
| 215 | * Whether the repository's owner has closed the door for reports from outside. | |
| 216 | * Read from the row every time (a primary-key lookup), never from memory: a | |
| 217 | * close made on another connection or by another process holds here at once | |
| 218 | * (#15039). | |
| 218 | 219 | */ |
| 219 | const closedSets = new WeakMap<Database, Set<string>>(); | |
| 220 | function closedSet(db: Database): Set<string> { | |
| 221 | let set = closedSets.get(db); | |
| 222 | if (set === undefined) { | |
| 223 | set = new Set( | |
| 224 | (db.query("SELECT repo_id AS id FROM report_closed").all() as { id: string }[]).map((r) => r.id), | |
| 225 | ); | |
| 226 | closedSets.set(db, set); | |
| 227 | } | |
| 228 | return set; | |
| 229 | } | |
| 230 | ||
| 231 | /** Whether the repository's owner has closed the door for reports from outside. */ | |
| 232 | export const reportsClosed = (db: Database, repoId: string): boolean => closedSet(db).has(repoId); | |
| 220 | export const reportsClosed = (db: Database, repoId: string): boolean => | |
| 221 | db.query("SELECT 1 FROM report_closed WHERE repo_id = ?1").get(repoId) !== null; | |
| 233 | 222 | |
| 234 | 223 | export function setReportsClosed(db: Database, repoId: string, closed: boolean): void { |
| 235 | 224 | if (closed) db.query("INSERT OR IGNORE INTO report_closed (repo_id) VALUES (?1)").run(repoId); |
| 236 | 225 | else db.query("DELETE FROM report_closed WHERE repo_id = ?1").run(repoId); |
| 237 | if (closed) closedSet(db).add(repoId); | |
| 238 | else closedSet(db).delete(repoId); | |
| 239 | 226 | } |
| 240 | 227 | |
| 241 | 228 | export function countWaiting(db: Database, repoId: string): number { |
new above
offline