A v2 versioning write costs queries proportional to the flag's segment overrides
维护者通常 1 天内回复
@Ishita-Singh-12 已经在做这个了。
开始于 2026年10月3日。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 55/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
- 领域
- backend, performance
调研方向
从 api/features/models.py 中的 FeatureState.clone 和 FeatureSegment.clone 开始,然后使用报告的 CaptureQueriesContext 测量结果跟踪 EnvironmentFeatureVersion.objects.create(...) 和 version.publish(...)。检查 publish 路径及其 signal handler,查找按 state 进行的关系查找,并添加一个覆盖所选优化范围的服务级查询计数测试。
由索引模型根据 Issue 内容生成。
描述
Every write to a flag in a v2-versioned environment opens a new EnvironmentFeatureVersion and publishes it. Both halves of that cost grow with the number of feature states the flag has, so a flag with many segment overrides pays a query count proportional to its overrides.
Measured on main with CaptureQueriesContext around EnvironmentFeatureVersion.objects.create(...) and version.publish(...), for a flag with 1 and with 3 segment overrides (2 and 4 feature states):
| Step | 1 override | 3 overrides | Per extra state |
|---|---|---|---|
EnvironmentFeatureVersion.objects.create |
26 | 54 | ~8 |
version.publish |
45 | 61 | ~5 |
Extrapolated, a flag with 50 segment overrides costs roughly 400 queries to open a version and 250 to publish it. Every v2 write path pays this: the versioning serializers, change request commits, and the experimental update-flag endpoints alike.
Creating a version copies row by row
FeatureState.clone (api/features/models.py:661) is a deepcopy plus save() per state, and FeatureSegment.clone (api/features/models.py:328) does the same. Per cloned state the create issues, roughly:
SELECT features_featureSELECT features_featurestatevalueINSERT features_featurestateandINSERT features_historicalfeaturestateINSERT features_featurestatevalueandINSERT features_historicalfeaturestatevalue- a
SAVEPOINT/RELEASEpair
Some copying is inherent to immutable versions, but the row-at-a-time shape is not: bulk_create for the states and their values, with the history rows batched alongside, would collapse most of it.
Publishing re-fetches relations per state
This half looks like a plain N+1 rather than inherent work. Between 1 and 3 overrides, publish goes from 45 to 61 queries, and the growth is all in per-state relation lookups:
| Query | 1 override | 3 overrides |
|---|---|---|
SELECT multivariate_multivariatefeaturestatevalue |
6 | 10 |
SELECT features_feature |
4 | 8 |
SELECT features_featurestatevalue |
4 | 8 |
SELECT features_featuresegment |
3 | 7 |
Whatever the publish path and its signal handlers iterate should be able to hydrate these with select_related / prefetch_related in one pass.
Suggested scope
- Flatten the publish-side N+1 first — it is the cheaper fix and is not intrinsic to versioning.
- Then consider bulk-creating the cloned states, values and multivariate values when a version is created.
Worth pinning either fix with a query-count test at the service level.
- 主要语言
- Python
- 星标
- 9.9k
- 派生
- 658
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 168
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Flagsmith/flagsmith 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
Flagsmith/flagsmith#9119 · 1 条评论 ·
维护者通常 1 天内回复
-
Fix Button Alignment in SDK Installation Section可能已有人在做 @manueldezman 于 3 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 62/100
Flagsmith/flagsmith#9056 · 2 条评论 ·
维护者通常 1 天内回复
-
Cloud Python warehouse snippet omits the import needed by its short-lived-job guidance可能已有人在做 @jcd1991 于 4 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 75/100
Flagsmith/flagsmith#9045 · 1 条评论 ·
维护者通常 1 天内回复
-
Expose whether an organisation is blocked for API usage可能已有人在做 @PiUnknown 于 38 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 62/100
Flagsmith/flagsmith#8773 · 1 条评论 ·
维护者通常 1 天内回复
-
influx_query_manager doesn't catch ApiException, so Influx error responses 500可能已有人在做 @SAY-5 于 13 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
Flagsmith/flagsmith#8510 · 1 条评论 ·
维护者通常 1 天内回复
查看 Flagsmith/flagsmith 的全部 Issue
相似的 Issue
-
ui
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
ARTPARK-SAHAI-ORG/calibrate-frontend#919 ·
维护者通常 1 天内回复
-
CI: MSYS2 jobs fail — mingw python3 package renamed upstream to python可能已有人在做 @ronaldtse 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 76/100
pydantic/pytest-examples#102 · 1 条评论 ·