Skip to content

Commit bbcdf16

Browse files
committed
缓存策略列表支持搜索
1 parent d62a44b commit bbcdf16

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

internal/db/models/http_cache_policy_dao.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,25 @@ func (this *HTTPCachePolicyDAO) ComposeCachePolicy(tx *dbs.Tx, policyId int64) (
210210
}
211211

212212
// CountAllEnabledHTTPCachePolicies 计算可用缓存策略数量
213-
func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx) (int64, error) {
214-
return this.Query(tx).
215-
State(HTTPCachePolicyStateEnabled).
216-
Count()
213+
func (this *HTTPCachePolicyDAO) CountAllEnabledHTTPCachePolicies(tx *dbs.Tx, keyword string) (int64, error) {
214+
query := this.Query(tx).
215+
State(HTTPCachePolicyStateEnabled)
216+
if len(keyword) > 0 {
217+
query.Where("(name LIKE :keyword)").
218+
Param("keyword", "%"+keyword+"%")
219+
}
220+
return query.Count()
217221
}
218222

219223
// ListEnabledHTTPCachePolicies 列出单页的缓存策略
220-
func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, offset int64, size int64) ([]*serverconfigs.HTTPCachePolicy, error) {
221-
ones, err := this.Query(tx).
222-
State(HTTPCachePolicyStateEnabled).
224+
func (this *HTTPCachePolicyDAO) ListEnabledHTTPCachePolicies(tx *dbs.Tx, keyword string, offset int64, size int64) ([]*serverconfigs.HTTPCachePolicy, error) {
225+
query := this.Query(tx).
226+
State(HTTPCachePolicyStateEnabled)
227+
if len(keyword) > 0 {
228+
query.Where("(name LIKE :keyword)").
229+
Param("keyword", "%"+keyword+"%")
230+
}
231+
ones, err := query.
223232
ResultPk().
224233
Offset(offset).
225234
Limit(size).

internal/rpc/services/service_http_cache_policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (this *HTTPCachePolicyService) CountAllEnabledHTTPCachePolicies(ctx context
100100

101101
tx := this.NullTx()
102102

103-
count, err := models.SharedHTTPCachePolicyDAO.CountAllEnabledHTTPCachePolicies(tx)
103+
count, err := models.SharedHTTPCachePolicyDAO.CountAllEnabledHTTPCachePolicies(tx, req.Keyword)
104104
if err != nil {
105105
return nil, err
106106
}
@@ -117,7 +117,7 @@ func (this *HTTPCachePolicyService) ListEnabledHTTPCachePolicies(ctx context.Con
117117

118118
tx := this.NullTx()
119119

120-
cachePolicies, err := models.SharedHTTPCachePolicyDAO.ListEnabledHTTPCachePolicies(tx, req.Offset, req.Size)
120+
cachePolicies, err := models.SharedHTTPCachePolicyDAO.ListEnabledHTTPCachePolicies(tx, req.Keyword, req.Offset, req.Size)
121121
if err != nil {
122122
return nil, err
123123
}

0 commit comments

Comments
 (0)