common版本更新v0.2.6;数据库查询接口增加是否从缓存中查询数据开关
This commit is contained in:
@@ -14,9 +14,17 @@ import (
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
var Advertisement = &advertisement{}
|
||||
var Advertisement = &advertisement{
|
||||
NoCache: true,
|
||||
}
|
||||
|
||||
type advertisement struct{}
|
||||
type advertisement struct {
|
||||
NoCache bool
|
||||
}
|
||||
|
||||
func (d *advertisement) SetNoCache() {
|
||||
Advertisement.NoCache = true
|
||||
}
|
||||
|
||||
// Insert 插入广告
|
||||
func (d *advertisement) Insert(ctx context.Context, advertisement *entity.Advertisement) (err error) {
|
||||
@@ -173,7 +181,7 @@ func (d *advertisement) GetOne(ctx context.Context, id string) (advertisement *e
|
||||
filter := bson.M{"_id": objectId}
|
||||
|
||||
advertisement = &entity.Advertisement{}
|
||||
err = mongo.FindOne(ctx, filter, advertisement, entity.AdvertisementCollection)
|
||||
err = mongo.FindOne(ctx, d.NoCache, filter, advertisement, entity.AdvertisementCollection)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -215,7 +223,7 @@ func (d *advertisement) buildListFilter(req *dto.ListAdvertisementReq) bson.M {
|
||||
|
||||
// checkTotalCount 检查总数
|
||||
func (d *advertisement) checkTotalCount(ctx context.Context, filter bson.M) (total int64, err error) {
|
||||
total, err = mongo.Count(ctx, filter, entity.AdvertisementCollection)
|
||||
total, err = mongo.Count(ctx, d.NoCache, filter, entity.AdvertisementCollection)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -248,6 +256,6 @@ func (d *advertisement) List(ctx context.Context, req *dto.ListAdvertisementReq)
|
||||
|
||||
opts := options.Find().SetLimit(limit).SetSkip(skip).SetSort(sort)
|
||||
|
||||
err = mongo.Find(ctx, filter, &list, entity.AdvertisementCollection, opts)
|
||||
err = mongo.Find(ctx, d.NoCache, filter, &list, entity.AdvertisementCollection, opts)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user