backfill: database handles are published on globalThis
I maintainer di solito rispondono entro 3 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Refactoring
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- postgresql, typescript
Direzione di ricerca
Read src/db.ts, src/backfill/gaps.ts, and scripts/backfill.ts, then compare the three approaches listed in the issue. Start by tracing how the database handles are initialized and how tests load gaps.ts; the existing issue describes failures from two attempted changes. Done means choosing and implementing a deliberate dependency approach that avoids those failures while removing or containing the untyped global access.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
#385 wires the backfill modules to the database through globals:
// src/db.ts
;(globalThis as any).__lens_prisma = prisma
;(globalThis as any).__lens_pgPool = pgPool
// src/backfill/gaps.ts
function getPrisma() { return (globalThis as any).__lens_prisma }
Why it was done this way, and it is a real constraint. src/backfill/gaps.ts must not import ../db at module load. Several suites mock ../config only partially, and importing db.ts evaluates config.db.url at load time — so an eager import makes unrelated tests fail with Cannot read properties of undefined (reading 'url'). The globals are a decoupling seam, not laziness.
Why it is still worth changing. src/db.ts runs in the API process, not just the CLI, so every request handler shares a process where a live Prisma client and pg pool are reachable as globalThis.__lens_prisma by any code at all — including a dependency that never imported them. It is also untyped on both ends, so a refactor of db.ts will not surface here.
What I tried and why it is not a quick fix. I attempted two versions while merging and reverted both:
- Importing the handles in
gaps.tswith the global as an override — breaks 6 suites on the load-timeconfig.db.urlevaluation described above. - Moving the installation into
scripts/backfill.tsand making the accessors throw when absent — breaks 33 suites, because the API routes reachgaps.tswithout installing anything.
So it needs a deliberate approach rather than an in-flight patch. Options worth weighing:
- Make
src/db.tslazy — build the client on first use rather than at module load — which removes the reason for the seam entirely and is probably the real fix. - Pass the handles in as arguments to the backfill functions, so the dependency is explicit and the tests inject rather than mock.
- Keep the seam but confine it: a small
src/backfill/handles.tswith typed getters and a setter, so at least it is typed, greppable and not onglobalThis.
Not urgent — the current arrangement works and the feature is live. Worth doing before anything else starts reading those globals, because every new reader makes it harder to remove.
- Lingua principale
- TypeScript
- Stelle
- 4
- Fork
- 71
- Merge medio
- 3g 14h
- PR unite (30g)
- 157
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Divinity-Labs/Lens
-
Webhook retries have no jitter, so failures synchroniseForse già presa @Richard-tobi l’ha presa 11 giorni fa. Apertaarea:reliability difficulty:easy help wanted points:100 Stellar Wave
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
Divinity-Labs/Lens#341 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 3 giorni
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
Divinity-Labs/Lens#626 ·
I maintainer di solito rispondono entro 3 giorni
-
area:tests automated live-spec-report
Difficoltà 4/5 3-5 giorni Idoneità per principianti 28/100
Divinity-Labs/Lens#606 · 4 commenti ·
I maintainer di solito rispondono entro 3 giorni
-
The key is accepted only as a bearer token, and nothing says soForse già presa @krsnak l’ha presa 10 giorni fa. Apertaarea:docs difficulty:easy help wanted points:100 Stellar Wave
Divinity-Labs/Lens#512 · 4 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 3 giorni
-
The admin surface has no testsForse già presa @krsnak l’ha presa 10 giorni fa. Apertaarea:testing difficulty:intermediate help wanted points:150 Stellar Wave
Divinity-Labs/Lens#510 · 5 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di Divinity-Labs/Lens
Issue simili
-
comp/desktop desktop/shell os/windows P3 tool/file type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
NousResearch/hermes-agent#145928 ·
I maintainer di solito rispondono entro 1 giorno
-
compiler-dom: stringifyStatic renders :disabled="0" as a present attributeForse già presa @DaZuiZui l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
vuejs/core#16051 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 74/100
-
integration:coding-agents
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 83/100
vectorize-io/hindsight#6151 ·
I maintainer di solito rispondono entro 1 giorno
-
DogFooding
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
OpenAEV-Platform/openaev#8768 ·
I maintainer di solito rispondono entro 1 giorno