backfill: database handles are published on globalThis
维护者通常 3 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 重构
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- postgresql, typescript
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
#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.
- 主要语言
- TypeScript
- 星标
- 4
- 派生
- 71
- 平均合并
- 3 天 15 小时
- 30 天内合并 PR
- 157
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Divinity-Labs/Lens 的其他 Issue
-
Webhook retries have no jitter, so failures synchronise可能已有人在做 @Richard-tobi 于 13 天前认领。 未关闭area:reliability difficulty:easy help wanted points:100 Stellar Wave
难度 2/5 1-3 小时 新手友好度 80/100
Divinity-Labs/Lens#341 · 2 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 35/100
Divinity-Labs/Lens#626 ·
维护者通常 3 天内回复
-
area:tests automated live-spec-report
难度 4/5 3-5 天 新手友好度 28/100
Divinity-Labs/Lens#606 · 6 条评论 ·
维护者通常 3 天内回复
-
The key is accepted only as a bearer token, and nothing says so可能已有人在做 @krsnak 于 12 天前认领。 未关闭area:docs difficulty:easy help wanted points:100 Stellar Wave
Divinity-Labs/Lens#512 · 4 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
The admin surface has no tests可能已有人在做 @krsnak 于 12 天前认领。 未关闭area:testing difficulty:intermediate help wanted points:150 Stellar Wave
Divinity-Labs/Lens#510 · 5 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
查看 Divinity-Labs/Lens 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
components-web-app/docs#307 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
localstack/localstack-mcp-server#112 ·
维护者通常 1 天内回复
-
area:frontend kind:bug priority:p1 ready
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
bug ready-for-agent
难度 2/5 1-3 小时 新手友好度 73/100
PhyberApex/kuroshiro#1687 ·
维护者通常 1 天内回复
-
Performance (Web Vitals) collector: LCP/FCP from background tabs are not discarded, inflating p75未关闭
难度 2/5 1-3 小时 新手友好度 74/100
umami-software/umami#4720 ·
维护者通常 3 天内回复