fix(database/gdb): Resolve the cache error overwriting caused by the use of fixed cache keys in pagination queries.#4339
Merged
hailaz merged 9 commits intogogf:masterfrom Jan 16, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a cache key collision issue in the GoFrame database ORM where AllAndCount and ScanAndCount methods were incorrectly sharing the same cache key for both count and select operations, causing incorrect query results.
- Introduces a new cache prefix constant
cachePrefixCountCacheto differentiate count queries from select queries - Modifies
AllAndCountandScanAndCountmethods to use prefixed cache keys for count operations - Ensures count queries use
SelectCache:CountCache:prefix to avoid cache conflicts with select queries
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| database/gdb/gdb.go | Adds new cache prefix constant for count operations |
| database/gdb/gdb_model_select.go | Updates AllAndCount and ScanAndCount to use prefixed cache keys for count queries |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- 在 Model 结构体中新增 pageCacheOption 字段用于分页缓存配置 - 新增 PageCache 方法支持为分页查询设置独立的缓存选项 - 修改分页查询逻辑,分别对 count 和数据查询应用不同的缓存策略- 优化缓存键名生成逻辑以适应分页场景 - 保持事务中禁用缓存特性的原有行为
hailaz
approved these changes
Jan 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
执行这段查询后
g.DumpJson(result)的结果是[ { "COUNT(1)": 5 } ],但是正确结果应该是五条用户信息,查看源代码后发现先执行的count查询和后来select查询都是直接使用了VIP这个缓存key,在redis中实际缓存key是SelectCache:VIP,第二步查询select获得的是count查询的缓存,所以查询结果是错的。 因此为Model增加一个PageCache方法允许用户分别设置count query和data query的缓存参数然后
AllAndCount在查询时分别给两个查询设置对应的缓存参数ScanAndCount同理