mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-03-20 23:07:29 +01:00
Pass reqKey as CacheKey
Entire-Checkpoint: b95ef43221bb
This commit is contained in:
@@ -676,10 +676,10 @@ func (r *queryResolver) JobsStatistics(ctx context.Context, filter []*model.JobF
|
|||||||
// Use request-scoped cache: multiple aliases with same (filter, groupBy)
|
// Use request-scoped cache: multiple aliases with same (filter, groupBy)
|
||||||
// but different sortBy/page hit the DB only once.
|
// but different sortBy/page hit the DB only once.
|
||||||
if cache := getStatsGroupCache(ctx); cache != nil {
|
if cache := getStatsGroupCache(ctx); cache != nil {
|
||||||
key := statsCacheKey(filter, groupBy)
|
key := statsCacheKey(filter, groupBy, reqFields)
|
||||||
var allStats []*model.JobsStatistics
|
var allStats []*model.JobsStatistics
|
||||||
allStats, err = cache.getOrCompute(key, func() ([]*model.JobsStatistics, error) {
|
allStats, err = cache.getOrCompute(key, func() ([]*model.JobsStatistics, error) {
|
||||||
return r.Repo.JobsStatsGrouped(ctx, filter, nil, nil, groupBy, nil)
|
return r.Repo.JobsStatsGrouped(ctx, filter, nil, nil, groupBy, reqFields)
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
stats = sortAndPageStats(allStats, sortBy, page)
|
stats = sortAndPageStats(allStats, sortBy, page)
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ func getStatsGroupCache(ctx context.Context) *statsGroupCache {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// cacheKey builds a deterministic string key from filter + groupBy.
|
// cacheKey builds a deterministic string key from filter + groupBy + reqFields.
|
||||||
func statsCacheKey(filter []*model.JobFilter, groupBy *model.Aggregate) string {
|
func statsCacheKey(filter []*model.JobFilter, groupBy *model.Aggregate, reqFields map[string]bool) string {
|
||||||
return fmt.Sprintf("%v|%v", filter, *groupBy)
|
return fmt.Sprintf("%v|%v|%v", filter, *groupBy, reqFields)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getOrCompute returns cached results for the given key, computing them on
|
// getOrCompute returns cached results for the given key, computing them on
|
||||||
|
|||||||
Reference in New Issue
Block a user