common版本更新v0.2.6;数据库查询接口增加是否从缓存中查询数据开关
This commit is contained in:
@@ -14,9 +14,17 @@ import (
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
var Advertiser = &advertiser{}
|
||||
var Advertiser = &advertiser{
|
||||
NoCache: true,
|
||||
}
|
||||
|
||||
type advertiser struct{}
|
||||
type advertiser struct {
|
||||
NoCache bool
|
||||
}
|
||||
|
||||
func (d *advertiser) SetNoCache() {
|
||||
Advertiser.NoCache = true
|
||||
}
|
||||
|
||||
// Insert 插入广告主
|
||||
func (d *advertiser) Insert(ctx context.Context, advertiser *entity.Advertiser) (err error) {
|
||||
@@ -183,7 +191,7 @@ func (d *advertiser) Recharge(ctx context.Context, id string, amount int64, rema
|
||||
|
||||
// 先获取当前余额
|
||||
advertiser := &entity.Advertiser{}
|
||||
err = mongo.FindOne(ctx, filter, advertiser, entity.AdvertiserCollection)
|
||||
err = mongo.FindOne(ctx, d.NoCache, filter, advertiser, entity.AdvertiserCollection)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -218,7 +226,7 @@ func (d *advertiser) GetOne(ctx context.Context, id string) (advertiser *entity.
|
||||
filter := bson.M{"_id": objectId}
|
||||
|
||||
advertiser = &entity.Advertiser{}
|
||||
err = mongo.FindOne(ctx, filter, advertiser, entity.AdvertiserCollection)
|
||||
err = mongo.FindOne(ctx, d.NoCache, filter, advertiser, entity.AdvertiserCollection)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -260,7 +268,7 @@ func (d *advertiser) buildListFilter(req *dto.ListAdvertiserReq) bson.M {
|
||||
|
||||
// checkTotalCount 检查总数
|
||||
func (d *advertiser) checkTotalCount(ctx context.Context, filter bson.M) (total int64, err error) {
|
||||
total, err = mongo.Count(ctx, filter, entity.AdvertiserCollection)
|
||||
total, err = mongo.Count(ctx, d.NoCache, filter, entity.AdvertiserCollection)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -293,6 +301,6 @@ func (d *advertiser) List(ctx context.Context, req *dto.ListAdvertiserReq) (list
|
||||
|
||||
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(sort)
|
||||
|
||||
err = mongo.Find(ctx, filter, &list, entity.AdvertiserCollection, opts)
|
||||
err = mongo.Find(ctx, d.NoCache, filter, &list, entity.AdvertiserCollection, opts)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user