提供用户某日刷新/预热缓存数量查询API

This commit is contained in:
刘祥超
2023-05-28 18:00:51 +08:00
parent 1a6d160a33
commit 9d2ecf6822

View File

@@ -5,8 +5,10 @@ package services
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"github.com/TeaOSLab/EdgeAPI/internal/db/models" "github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/TeaOSLab/EdgeAPI/internal/utils" "github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/TeaOSLab/EdgeAPI/internal/utils/regexputils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/dbs" "github.com/iwind/TeaGo/dbs"
) )
@@ -182,3 +184,22 @@ func (this *HTTPCacheTaskKeyService) UpdateHTTPCacheTaskKeysStatus(ctx context.C
return this.Success() return this.Success()
} }
// CountHTTPCacheTaskKeysWithDay 计算当天已经清理的Key数量
func (this *HTTPCacheTaskKeyService) CountHTTPCacheTaskKeysWithDay(ctx context.Context, req *pb.CountHTTPCacheTaskKeysWithDayRequest) (*pb.RPCCountResponse, error) {
userId, err := this.ValidateUserNode(ctx, true)
if err != nil {
return nil, err
}
if !regexputils.YYYYMMDD.MatchString(req.Day) {
return nil, errors.New("invalid format 'day'")
}
var tx = this.NullTx()
countKeys, err := models.SharedHTTPCacheTaskKeyDAO.CountUserTasksInDay(tx, userId, req.Day, req.KeyType)
if err != nil {
return nil, err
}
return this.SuccessCount(countKeys)
}