Refactor: split the 1161-line functions.rs god-file into topical submodules

未关闭
#1,320 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
停滞
技术栈
rust
领域
backend

调研方向

Start with src/webserver/database/sqlpage_functions/functions.rs and the existing SQL function tests; read the short README requested for sqlpage_functions/ and inspect how the current macro registry discovers functions. The issue proposes one function per file plus removal of duplicated fetch pipelines, so confirm the discovery convention and scope before moving implementations. Done means topical modules are registered and existing function and end-to-end tests pass without behavior changes.

由索引模型根据 Issue 内容生成。

描述

Split functions.rs into one file per function

src/webserver/database/sqlpage_functions/functions.rs is a 1161-line god-file with no internal boundaries. It is one of the most-churned files in the DB module, and it mixes the registry of every built-in SQL function with ~40 unrelated implementations: HTTP fetch, password hashing, file persistence, regex, HMAC, OIDC claim extraction, subprocess exec, and the recursive run_sql engine entry point. Navigation is by scrolling, security-sensitive code sits next to unrelated helpers, and unit tests are interleaved with implementations.

$ wc -l src/webserver/database/sqlpage_functions/functions.rs
1161 src/webserver/database/sqlpage_functions/functions.rs

This splits out the refactor item from #1249 into a concrete, actionable issue.

Why this matters

Unrelated and security-sensitive concerns are interleaved in a single file, which raises cognitive load and regression risk on a file that changes often:

  • Subprocess exec sits a few lines from the HTTP request builders, run_sql (the recursive engine entry point) is in the same flat file as hash_password and hmac.
  • Unit tests are scattered between implementations rather than grouped, e.g. test_random_string, test_hash_password, test_hmac.
  • The duplicated HTTP fetch pipelines flagged in #1249 are still present: fetch and fetch_with_meta repeat the same tracing span setup, client creation, request build, and body preparation. Two copies of this pipeline is a drift hazard (a fix to one, like the body-log redaction in #1249, can silently miss the other).
  • The OIDC user_info claim resolver is a long hand-maintained 30+ arm match over claim names that has no business living next to subprocess and SQL execution code.
Proposed change

Split the implementations into topical submodules under sqlpage_functions/.
At compile time, iterate of files in the sqlpage_functions folder and generate one function per file. Use convention over configuration, adding a new file in the folder is all that should be needed to create a new sqlpage function.

The short readme in sqlpage_functions should explain the mechanism.

Risks and mitigations

Low risk; this is a mechanical move with no behavior change.

  • The macro registry keeps wiring centralized, so the public function surface does not change.
  • Move implementations file-by-file, one module at a time, each a self-contained reviewable commit.
  • Existing function tests (the interleaved test_* plus the end-to-end SQL function tests) pin behavior across the move.
Expected win

Better navigability and reviewability of a frequently-edited file, security-sensitive exec/run_sql isolated and easy to audit, and removing the fetch/fetch_with_meta duplication eliminates a drift hazard.

Refs #1249 (item 6).

主要语言
Rust
星标
2.6k
派生
175
平均合并
14 小时 16 分钟
30 天内合并 PR
43

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

sqlpage/SQLPage 的其他 Issue

查看 sqlpage/SQLPage 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。