common版本更新v0.2.6;数据库查询接口增加是否从缓存中查询数据开关
This commit is contained in:
@@ -9,26 +9,34 @@ import (
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
var AdSource = &adSourceDao{}
|
||||
var AdSource = &adSourceDao{
|
||||
NoCache: true,
|
||||
}
|
||||
|
||||
type adSourceDao struct{}
|
||||
type adSourceDao struct {
|
||||
NoCache bool
|
||||
}
|
||||
|
||||
func (d *adSourceDao) SetNoCache() {
|
||||
AdSource.NoCache = true
|
||||
}
|
||||
|
||||
// GetByName 根据名称获取广告源
|
||||
func (d *adSourceDao) GetByName(ctx context.Context, name string) (adSource *entity.AdSource, err error) {
|
||||
err = mongo.FindOne(ctx, bson.M{"name": name}, &adSource, "ad_sources")
|
||||
err = mongo.FindOne(ctx, d.NoCache, bson.M{"name": name}, &adSource, "ad_sources")
|
||||
return
|
||||
}
|
||||
|
||||
// GetAvailableSources 获取可用的广告源
|
||||
func (d *adSourceDao) GetAvailableSources(ctx context.Context) (list []*entity.AdSource, err error) {
|
||||
err = mongo.Find(ctx, bson.M{"status": "active"}, &list, "ad_sources",
|
||||
err = mongo.Find(ctx, d.NoCache, bson.M{"status": "active"}, &list, "ad_sources",
|
||||
options.Find().SetSort(bson.M{"priority": -1, "createdAt": 1}))
|
||||
return
|
||||
}
|
||||
|
||||
// GetSourcesByProvider 根据提供商获取广告源
|
||||
func (d *adSourceDao) GetSourcesByProvider(ctx context.Context, provider string) (list []*entity.AdSource, err error) {
|
||||
err = mongo.Find(ctx, bson.M{"provider": provider, "status": "active"}, &list, "ad_sources",
|
||||
err = mongo.Find(ctx, d.NoCache, bson.M{"provider": provider, "status": "active"}, &list, "ad_sources",
|
||||
options.Find().SetSort(bson.M{"priority": -1}))
|
||||
return
|
||||
}
|
||||
@@ -65,7 +73,7 @@ func (d *adSourceDao) Delete(ctx context.Context, id string) (affected int64, er
|
||||
|
||||
// GetByID 根据ID获取广告源
|
||||
func (d *adSourceDao) GetByID(ctx context.Context, id string) (adSource *entity.AdSource, err error) {
|
||||
err = mongo.FindOne(ctx, bson.M{"_id": id}, &adSource, "ad_sources")
|
||||
err = mongo.FindOne(ctx, d.NoCache, bson.M{"_id": id}, &adSource, "ad_sources")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user