文件存储-定时同步租户文件存储容量信息接口优化

This commit is contained in:
2025-12-29 14:42:56 +08:00
parent 36c9b61db0
commit e65bdeb229
5 changed files with 71 additions and 69 deletions

View File

@@ -7,9 +7,17 @@ import (
"oss/model/entity"
)
var File = &file{}
var File = &file{
NoCache: false,
}
type file struct{}
type file struct {
NoCache bool
}
func (d *file) SetNoCache() {
File.NoCache = true
}
// Insert 插入
func (d *file) Insert(ctx context.Context, entity *entity.File) (err error) {

View File

@@ -9,9 +9,17 @@ import (
"oss/model/entity"
)
var TenantOssTotal = &tenantOssTotal{}
var TenantOssTotal = &tenantOssTotal{
NoCache: false,
}
type tenantOssTotal struct{}
type tenantOssTotal struct {
NoCache bool
}
func (d *tenantOssTotal) SetNoCache() {
TenantOssTotal.NoCache = true
}
// Insert 插入
func (d *tenantOssTotal) Insert(ctx context.Context, entity []interface{}) (err error) {
@@ -20,12 +28,12 @@ func (d *tenantOssTotal) Insert(ctx context.Context, entity []interface{}) (err
}
// SaveOrUpdate 增加或更新
func (d *tenantOssTotal) SaveOrUpdate(ctx context.Context, filterData []*entity.TenantOssTotal, updateData []*entity.TenantOssTotal) (err error) {
func (d *tenantOssTotal) SaveOrUpdate(ctx context.Context, updateData []*entity.TenantOssTotal) (err error) {
if !g.IsEmpty(updateData) {
var filter, update []bson.M
for i, v := range filterData {
for _, v := range updateData {
filter = append(filter, bson.M{"tenantId": v.TenantId})
update = append(update, bson.M{"$set": bson.M{"usedOssSize": updateData[i].UsedOssSize, "totalOssSize": updateData[i].TotalOssSize}})
update = append(update, bson.M{"$set": bson.M{"usedOssSize": v.UsedOssSize, "totalOssSize": v.TotalOssSize}})
}
_, err = mongo.SaveOrUpdate(ctx, filter, update, consts.TenantOssTotalCollection)
}
@@ -35,6 +43,6 @@ func (d *tenantOssTotal) SaveOrUpdate(ctx context.Context, filterData []*entity.
func (d *tenantOssTotal) GetOneByTenantId(ctx context.Context, tenantId string) (e *entity.TenantOssTotal, err error) {
filter := bson.M{"tenantId": tenantId}
e = &entity.TenantOssTotal{}
err = mongo.FindOne(ctx, filter, e, consts.TenantOssTotalCollection)
err = mongo.FindOne(ctx, d.NoCache, filter, e, consts.TenantOssTotalCollection)
return
}