perf(server): cache speed limit calculations
Build docker and publish / build (20.15.1) (push) Successful in 5m37s
Build docker and publish / build (20.15.1) (push) Successful in 5m37s
This commit is contained in:
@@ -131,9 +131,15 @@ func (l *TrafficStatisticsLogic) ProcessTask(ctx context.Context, task *asynq.Ta
|
||||
|
||||
// 写完流量后检查是否触发按量限速,若触发则清除节点缓存使限速立即生效
|
||||
if planSub, planErr := l.svc.SubscribeModel.FindOne(ctx, sub.SubscribeId); planErr == nil &&
|
||||
(planSub.SpeedLimit > 0 || planSub.TrafficLimit != "") {
|
||||
planSub.TrafficLimit != "" {
|
||||
throttle := speedlimit.Calculate(ctx, l.svc.DB, sub.UserId, sub.Id, planSub.SpeedLimit, planSub.TrafficLimit)
|
||||
if throttle.IsThrottled {
|
||||
if delErr := speedlimit.ClearCache(ctx, l.svc.Redis, sub.UserId, sub.Id, planSub.SpeedLimit, planSub.TrafficLimit); delErr != nil {
|
||||
logger.WithContext(ctx).Error("[TrafficStatistics] Clear speed limit cache failed",
|
||||
logger.Field("subscribeId", sub.Id),
|
||||
logger.Field("error", delErr.Error()),
|
||||
)
|
||||
}
|
||||
cacheKey := fmt.Sprintf("%s%d", node.ServerUserListCacheKey, payload.ServerId)
|
||||
if delErr := l.svc.Redis.Del(ctx, cacheKey).Err(); delErr != nil {
|
||||
logger.WithContext(ctx).Error("[TrafficStatistics] Clear server user cache failed",
|
||||
|
||||
Reference in New Issue
Block a user