Skip to content

Commit

Permalink
Merge pull request #426 from penguin-statistics/dev
Browse files Browse the repository at this point in the history
Release v3.11.4
  • Loading branch information
AlvISsReimu authored Mar 17, 2023
2 parents 8ddb493 + 2997ae3 commit debf182
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions internal/model/cache/caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ var (
StagesMapByID *cache.Singular[map[int]*model.Stage]
StagesMapByArkID *cache.Singular[map[string]*model.Stage]

TimeRanges *cache.Set[[]*model.TimeRange]
TimeRangeByID *cache.Set[model.TimeRange]
TimeRangesMap *cache.Set[map[int]*model.TimeRange]
MaxAccumulableTimeRanges *cache.Set[map[int]map[int][]*model.TimeRange]
LatestTimeRanges *cache.Set[map[int]*model.TimeRange]
TimeRanges *cache.Set[[]*model.TimeRange]
TimeRangeByID *cache.Set[model.TimeRange]
TimeRangesMap *cache.Set[map[int]*model.TimeRange]
MaxAccumulableTimeRanges *cache.Set[map[int]map[int][]*model.TimeRange]
AllMaxAccumulableTimeRanges *cache.Set[map[int]map[int][]*model.TimeRange]
LatestTimeRanges *cache.Set[map[int]*model.TimeRange]

Zones *cache.Singular[[]*model.Zone]
ZoneByArkID *cache.Set[model.Zone]
Expand Down Expand Up @@ -204,12 +205,14 @@ func initializeCaches() {
TimeRangeByID = cache.NewSet[model.TimeRange]("timeRange#rangeId")
TimeRangesMap = cache.NewSet[map[int]*model.TimeRange]("timeRangesMap#server")
MaxAccumulableTimeRanges = cache.NewSet[map[int]map[int][]*model.TimeRange]("maxAccumulableTimeRanges#server")
AllMaxAccumulableTimeRanges = cache.NewSet[map[int]map[int][]*model.TimeRange]("allMaxAccumulableTimeRanges#server")
LatestTimeRanges = cache.NewSet[map[int]*model.TimeRange]("latestTimeRanges#server")

SetMap["timeRanges#server"] = TimeRanges.Flush
SetMap["timeRange#rangeId"] = TimeRangeByID.Flush
SetMap["timeRangesMap#server"] = TimeRangesMap.Flush
SetMap["maxAccumulableTimeRanges#server"] = MaxAccumulableTimeRanges.Flush
SetMap["allMaxAccumulableTimeRanges#server"] = AllMaxAccumulableTimeRanges.Flush
SetMap["latestTimeRanges#server"] = LatestTimeRanges.Flush

// zone
Expand Down
1 change: 1 addition & 0 deletions internal/service/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (s *Admin) SaveRenderedObjects(ctx context.Context, objects *gamedata.Rende
cache.TimeRanges.Delete(objects.TimeRange.Server)
cache.TimeRangesMap.Delete(objects.TimeRange.Server)
cache.MaxAccumulableTimeRanges.Delete(objects.TimeRange.Server)
cache.AllMaxAccumulableTimeRanges.Delete(objects.TimeRange.Server)
cache.LatestTimeRanges.Delete(objects.TimeRange.Server)
}

Expand Down
5 changes: 3 additions & 2 deletions internal/service/time_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ func (s *TimeRange) GetMaxAccumulableTimeRangesByServer(ctx context.Context, ser
}

// This function will combine time ranges together if they are adjacent
// Cache: allMaxAccumulableTimeRanges#server:{server}, 5 min
func (s *TimeRange) GetAllMaxAccumulableTimeRangesByServer(ctx context.Context, server string) (map[int]map[int][]*model.TimeRange, error) {
var maxAccumulableTimeRanges map[int]map[int][]*model.TimeRange
err := cache.MaxAccumulableTimeRanges.Get(server, &maxAccumulableTimeRanges)
err := cache.AllMaxAccumulableTimeRanges.Get(server, &maxAccumulableTimeRanges)
if err == nil {
return maxAccumulableTimeRanges, nil
}
Expand Down Expand Up @@ -242,7 +243,7 @@ func (s *TimeRange) GetAllMaxAccumulableTimeRangesByServer(ctx context.Context,
maxAccumulableTimeRanges[stageId] = maxAccumulableTimeRangesForOneStage
}
}
cache.MaxAccumulableTimeRanges.Set(server, maxAccumulableTimeRanges, time.Minute*5)
cache.AllMaxAccumulableTimeRanges.Set(server, maxAccumulableTimeRanges, time.Minute*5)
return maxAccumulableTimeRanges, nil
}

Expand Down

0 comments on commit debf182

Please sign in to comment.