Skip to content

Commit

Permalink
Merge pull request #436 from penguin-statistics/dev
Browse files Browse the repository at this point in the history
Release v3.11.12
  • Loading branch information
AlvISsReimu authored Apr 7, 2023
2 parents f079197 + c17fc6b commit a46f7c1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
2 changes: 1 addition & 1 deletion internal/controller/v2/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (c *Private) GetDropMatrix(ctx *fiber.Ctx) error {
if !accountId.Valid {
key := server + constant.CacheSep + "true" + constant.CacheSep + category
var lastModifiedTime time.Time
if err := cache.LastModifiedTime.Get("[shimGlobalDropMatrix#server|showClosedZoned|sourceCategory:"+key+"]", &lastModifiedTime); err != nil {
if err := cache.LastModifiedTime.Get("[shimGlobalDropMatrix#server|showClosedZones|sourceCategory:"+key+"]", &lastModifiedTime); err != nil {
lastModifiedTime = time.Now()
}
cachectrl.OptIn(ctx, lastModifiedTime)
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/v2/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (c *Result) GetDropMatrix(ctx *fiber.Ctx) error {
if useCache {
key := server + constant.CacheSep + strconv.FormatBool(showClosedZones) + constant.CacheSep + constant.SourceCategoryAll
var lastModifiedTime time.Time
if err := cache.LastModifiedTime.Get("[shimGlobalDropMatrix#server|showClosedZoned|sourceCategory:"+key+"]", &lastModifiedTime); err != nil {
if err := cache.LastModifiedTime.Get("[shimGlobalDropMatrix#server|showClosedZones|sourceCategory:"+key+"]", &lastModifiedTime); err != nil {
lastModifiedTime = time.Now()
}
cachectrl.OptIn(ctx, lastModifiedTime)
Expand Down
4 changes: 2 additions & 2 deletions internal/model/cache/caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ func initializeCaches() {
SetMap["itemDropSet#server|stageId|startTime|endTime"] = ItemDropSetByStageIdAndTimeRange.Flush

// drop_matrix
ShimGlobalDropMatrix = cache.NewSet[modelv2.DropMatrixQueryResult]("shimGlobalDropMatrix#server|showClosedZoned|sourceCategory")
ShimGlobalDropMatrix = cache.NewSet[modelv2.DropMatrixQueryResult]("shimGlobalDropMatrix#server|showClosedZones|sourceCategory")

SetMap["shimGlobalDropMatrix#server|showClosedZoned|sourceCategory"] = ShimGlobalDropMatrix.Flush
SetMap["shimGlobalDropMatrix#server|showClosedZones|sourceCategory"] = ShimGlobalDropMatrix.Flush

// trend
ShimTrend = cache.NewSet[modelv2.TrendQueryResult]("shimTrend#server")
Expand Down
35 changes: 32 additions & 3 deletions internal/service/drop_matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewDropMatrix(

// =========== Global & Personal, Max Accumulable ===========

// Cache: shimGlobalDropMatrix#server|showClosedZoned|sourceCategory:{server}|{showClosedZones}|{sourceCategory}, 24 hrs, records last modified time
// Cache: shimGlobalDropMatrix#server|showClosedZones|sourceCategory:{server}|{showClosedZones}|{sourceCategory}, 24 hrs, records last modified time
// Called by frontend, used for both global and personal, only for max accumulable results
func (s *DropMatrix) GetShimDropMatrix(
ctx context.Context, server string, showClosedZones bool, stageFilterStr string, itemFilterStr string, accountId null.Int, sourceCategory string,
Expand Down Expand Up @@ -82,7 +82,7 @@ func (s *DropMatrix) GetShimDropMatrix(
if err != nil {
return nil, err
} else if calculated {
cache.LastModifiedTime.Set("[shimGlobalDropMatrix#server|showClosedZoned|sourceCategory:"+key+"]", time.Now(), 0)
cache.LastModifiedTime.Set("[shimGlobalDropMatrix#server|showClosedZones|sourceCategory:"+key+"]", time.Now(), 0)
}
} else {
return valueFunc()
Expand Down Expand Up @@ -328,7 +328,17 @@ func (s *DropMatrix) calcGlobalDropMatrix(ctx context.Context, server string, so
latestMaxAccumulableTimeRanges[stageId] = make(map[int]*model.TimeRange, 0)
}
for itemId, timeRanges := range timeRangesMapByItemId {
latestMaxAccumulableTimeRanges[stageId][itemId] = timeRanges[len(timeRanges)-1]
timeRangeToAdd := timeRanges[len(timeRanges)-1]
latestMaxAccumulableTimeRanges[stageId][itemId] = timeRangeToAdd

// TODO: remove this after debugging
if server == "CN" && stageId == 18 && itemId == 7 && sourceCategory == "all" {
log.Info().
Str("evt.name", "debug.drop_matrix.endtime").
Int64("StartTime", timeRangeToAdd.StartTime.UnixMilli()).
Int64("EndTime", timeRangeToAdd.EndTime.UnixMilli()).
Msg("EndTime at the end of generating latestMaxAccumulableTimeRanges")
}
}
}

Expand Down Expand Up @@ -388,6 +398,16 @@ func (s *DropMatrix) calcGlobalDropMatrix(ctx context.Context, server string, so
StdDev: util.RoundFloat64(util.CalcStdDevFromQuantityBuckets(quantityUniqCountResult.QuantityBuckets, timesResult.Times, false), constant.StdDevDigits),
}
finalResult.Matrix = append(finalResult.Matrix, oneDropMatrixElement)

// TODO: remove this after debugging
if server == "CN" && stageId == 18 && itemId == 7 && sourceCategory == "all" {
log.Info().
Str("evt.name", "debug.drop_matrix.endtime").
Int64("StartTime", timeRange.StartTime.UnixMilli()).
Int64("EndTime", timeRange.EndTime.UnixMilli()).
Str("timeRangeStr", timeRangeStr).
Msg("EndTime at the end of calcGlobalDropMatrix")
}
}
}
}
Expand Down Expand Up @@ -932,6 +952,15 @@ func (s *DropMatrix) applyShimForDropMatrixQuery(ctx context.Context, server str
EndTime: endTime,
}
results.Matrix = append(results.Matrix, &oneDropMatrixElement)

// TODO: remove this after debugging
if server == "CN" && stage.ArkStageID == "main_01-07" && item.ArkItemID == "30012" && stageFilterStr == "" && itemFilterStr == "" {
log.Info().
Str("evt.name", "debug.drop_matrix.endtime").
Int64("StartTime", el.TimeRange.StartTime.UnixMilli()).
Int64("EndTime", endTime.Int64).
Msg("EndTime at the end of applyShimForDropMatrixQuery")
}
}
return results, nil
}
3 changes: 1 addition & 2 deletions internal/service/pattern_matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ func (s *PatternMatrix) GetShimPatternMatrix(ctx context.Context, server string,

var results modelv2.PatternMatrixQueryResult
if !accountId.Valid {
key := server + constant.CacheSep + sourceCategory
key := server + constant.CacheSep + sourceCategory + constant.CacheSep + strconv.FormatBool(showAllPatterns)
calculated, err := cache.ShimGlobalPatternMatrix.MutexGetSet(key, &results, valueFunc, 24*time.Hour)
if err != nil {
return nil, err
} else if calculated {
key := server + constant.CacheSep + sourceCategory + constant.CacheSep + strconv.FormatBool(showAllPatterns)
cache.LastModifiedTime.Set("[shimGlobalPatternMatrix#server|sourceCategory|showAllPatterns:"+key+"]", time.Now(), 0)
}
return &results, nil
Expand Down
11 changes: 10 additions & 1 deletion internal/service/time_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/ahmetb/go-linq/v3"
"github.com/rs/zerolog/log"

"exusiai.dev/backend-next/internal/model"
"exusiai.dev/backend-next/internal/model/cache"
Expand Down Expand Up @@ -66,7 +67,7 @@ func (s *TimeRange) GetCurrentTimeRangesByServer(ctx context.Context, server str
return timeRanges, nil
}

// Cache: timeRangesMap#server:{server}, 1 hr
// Cache: timeRangesMap#server:{server}, 5 min
func (s *TimeRange) GetTimeRangesMap(ctx context.Context, server string) (map[int]*model.TimeRange, error) {
var timeRangesMap map[int]*model.TimeRange
err := cache.TimeRangesMap.Get(server, &timeRangesMap)
Expand Down Expand Up @@ -238,6 +239,14 @@ func (s *TimeRange) GetAllMaxAccumulableTimeRangesByServer(ctx context.Context,
if len(timeRanges) > 0 {
maxAccumulableTimeRangesForOneStage[itemId] = timeRanges
}

// TODO: remove this after debugging
if server == "CN" && stageId == 18 && itemId == 7 {
log.Info().
Str("evt.name", "debug.drop_matrix.endtime").
Interface("timeRanges", timeRanges).
Msg("timeRanges at the end of GetAllMaxAccumulableTimeRangesByServer")
}
}
if len(maxAccumulableTimeRangesForOneStage) > 0 {
maxAccumulableTimeRanges[stageId] = maxAccumulableTimeRangesForOneStage
Expand Down
5 changes: 3 additions & 2 deletions internal/service/trend.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ func (s *Trend) GetShimTrend(ctx context.Context, server string) (*modelv2.Trend
}

var shimResult modelv2.TrendQueryResult
calculated, err := cache.ShimTrend.MutexGetSet(server, &shimResult, valueFunc, 24*time.Hour)
key := server
calculated, err := cache.ShimTrend.MutexGetSet(key, &shimResult, valueFunc, 24*time.Hour)
if err != nil {
return nil, err
} else if calculated {
cache.LastModifiedTime.Set("[shimTrend#server:"+server+"]", time.Now(), 0)
cache.LastModifiedTime.Set("[shimTrend#server:"+key+"]", time.Now(), 0)
}
return &shimResult, nil
}
Expand Down

0 comments on commit a46f7c1

Please sign in to comment.