common版本更新v0.2.6;数据库查询接口增加是否从缓存中查询数据开关
This commit is contained in:
@@ -10,9 +10,17 @@ import (
|
||||
)
|
||||
|
||||
// applicationDao 应用DAO
|
||||
type applicationDao struct{}
|
||||
type applicationDao struct {
|
||||
NoCache bool
|
||||
}
|
||||
|
||||
var Application = &applicationDao{}
|
||||
var Application = &applicationDao{
|
||||
NoCache: true,
|
||||
}
|
||||
|
||||
func (d *applicationDao) SetNoCache() {
|
||||
Application.NoCache = true
|
||||
}
|
||||
|
||||
// Create 创建应用
|
||||
func (d *applicationDao) Create(ctx context.Context, app *entity.Application) (string, error) {
|
||||
@@ -29,21 +37,23 @@ func (d *applicationDao) Create(ctx context.Context, app *entity.Application) (s
|
||||
// GetByID 根据ID获取应用
|
||||
func (d *applicationDao) GetByID(ctx context.Context, id string) (*entity.Application, error) {
|
||||
var app *entity.Application
|
||||
err := mongo.FindOne(ctx, bson.M{"_id": id}, &app, "application")
|
||||
err := mongo.FindOne(ctx, d.NoCache, bson.M{"_id": id}, &app, "application")
|
||||
return app, err
|
||||
}
|
||||
|
||||
// GetByTenantID 根据租户ID获取应用列表
|
||||
func (d *applicationDao) GetByTenantID(ctx context.Context, tenantID string) ([]*entity.Application, error) {
|
||||
var apps []*entity.Application
|
||||
err := mongo.Find(ctx, bson.M{"tenantId": tenantID}, &apps, "application")
|
||||
err := mongo.Find(ctx, d.NoCache,
|
||||
bson.M{"tenantId": tenantID}, &apps, "application")
|
||||
return apps, err
|
||||
}
|
||||
|
||||
// GetByAPIKey 根据API密钥获取应用
|
||||
func (d *applicationDao) GetByAPIKey(ctx context.Context, apiKey string) (*entity.Application, error) {
|
||||
var app *entity.Application
|
||||
err := mongo.FindOne(ctx, bson.M{"appKey": apiKey}, &app, "application")
|
||||
err := mongo.FindOne(ctx, d.NoCache,
|
||||
bson.M{"appKey": apiKey}, &app, "application")
|
||||
return app, err
|
||||
}
|
||||
|
||||
@@ -67,13 +77,13 @@ func (d *applicationDao) List(ctx context.Context, tenantID string, page, pageSi
|
||||
}
|
||||
|
||||
var apps []*entity.Application
|
||||
total, err := mongo.Count(ctx, filter, "application")
|
||||
total, err := mongo.Count(ctx, d.NoCache, filter, "application")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
err = mongo.Find(ctx, filter, &apps, "application",
|
||||
err = mongo.Find(ctx, d.NoCache, filter, &apps, "application",
|
||||
options.Find().SetSort(bson.M{"createdAt": -1}).
|
||||
SetSkip(int64(offset)).
|
||||
SetLimit(int64(pageSize)))
|
||||
@@ -87,7 +97,7 @@ func (d *applicationDao) List(ctx context.Context, tenantID string, page, pageSi
|
||||
// GetByName 根据名称获取应用
|
||||
func (d *applicationDao) GetByName(ctx context.Context, name string) (*entity.Application, error) {
|
||||
var app *entity.Application
|
||||
err := mongo.FindOne(ctx, bson.M{"name": name}, &app, "application")
|
||||
err := mongo.FindOne(ctx, d.NoCache, bson.M{"name": name}, &app, "application")
|
||||
return app, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user