From cac1a08a065c14df02bb967a8557b1aed66e5776 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Mon, 7 Jun 2021 08:44:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=AD=96=E7=95=A5=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=94=AF=E6=8C=81=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/db/models/http_cache_policy_dao.go | 23 +++++++++++++------ .../rpc/services/service_http_cache_policy.go | 4 ++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/internal/db/models/http_cache_policy_dao.go b/internal/db/models/http_cache_policy_dao.go index c0e4414f..55be7e2e 100644 --- a/internal/db/models/http_cache_policy_dao.go +++ b/internal/db/models/http_cache_policy_dao.go @@ -210,16 +210,25 @@ func (this *HTTPCachePolicyDAO) ComposeCachePolicy(tx *dbs.Tx, policyId int64) ( } // CountAllEnabledHTTPCachePolicies 计算可用缓存策略数量 -func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx) (int64, error) { - return this.Query(tx). - State(HTTPCachePolicyStateEnabled). - Count() +func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx, keyword string) (int64, error) { + query := this.Query(tx). + State(HTTPCachePolicyStateEnabled) + if len(keyword) > 0 { + query.Where("(name LIKE :keyword)"). + Param("keyword", "%"+keyword+"%") + } + return query.Count() } // ListEnabledHTTPCachePolicies 列出单页的缓存策略 -func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, offset int64, size int64) ([]*serverconfigs.HTTPCachePolicy, error) { - ones, err := this.Query(tx). - State(HTTPCachePolicyStateEnabled). +func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, keyword string, offset int64, size int64) ([]*serverconfigs.HTTPCachePolicy, error) { + query := this.Query(tx). + State(HTTPCachePolicyStateEnabled) + if len(keyword) > 0 { + query.Where("(name LIKE :keyword)"). + Param("keyword", "%"+keyword+"%") + } + ones, err := query. ResultPk(). Offset(offset). Limit(size). diff --git a/internal/rpc/services/service_http_cache_policy.go b/internal/rpc/services/service_http_cache_policy.go index 98445aca..cef6ec32 100644 --- a/internal/rpc/services/service_http_cache_policy.go +++ b/internal/rpc/services/service_http_cache_policy.go @@ -100,7 +100,7 @@ func (this *HTTPCachePolicyService) CountAllEnabledHTTPCachePolicies(ctx context tx := this.NullTx() - count, err := models.SharedHTTPCachePolicyDAO.CountAllEnabledHTTPCachePolicies(tx) + count, err := models.SharedHTTPCachePolicyDAO.CountAllEnabledHTTPCachePolicies(tx, req.Keyword) if err != nil { return nil, err } @@ -117,7 +117,7 @@ func (this *HTTPCachePolicyService) ListEnabledHTTPCachePolicies(ctx context.Con tx := this.NullTx() - cachePolicies, err := models.SharedHTTPCachePolicyDAO.ListEnabledHTTPCachePolicies(tx, req.Offset, req.Size) + cachePolicies, err := models.SharedHTTPCachePolicyDAO.ListEnabledHTTPCachePolicies(tx, req.Keyword, req.Offset, req.Size) if err != nil { return nil, err }