This is an automated email from the ASF dual-hosted git repository.
littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-kie.git
The following commit(s) were added to refs/heads/master by this push:
new 4d91771 kvdoc增加优先级字段,查询结果支持优先级排序 (#296)
4d91771 is described below
commit 4d917719ec799272f7abff13e5a7393fb7bff246
Author: tornado-ssy <[email protected]>
AuthorDate: Sat Sep 16 16:56:40 2023 +0800
kvdoc增加优先级字段,查询结果支持优先级排序 (#296)
Co-authored-by: songshiyuan 00649746 <[email protected]>
---
pkg/model/db_schema.go | 1 +
server/datasource/etcd/history/history_dao.go | 5 +++--
server/datasource/etcd/kv/kv_dao.go | 9 +++++----
server/datasource/kv_sort.go | 7 +++++--
4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/pkg/model/db_schema.go b/pkg/model/db_schema.go
index 748f2c3..28b98d3 100644
--- a/pkg/model/db_schema.go
+++ b/pkg/model/db_schema.go
@@ -36,6 +36,7 @@ type KVDoc struct {
Key string `json:"key" yaml:"key"
validate:"min=1,max=2048,key"`
Value string `json:"value" yaml:"value"
validate:"max=131072,value"`
//128K
ValueType string `json:"value_type,omitempty"
bson:"value_type,omitempty" yaml:"value_type,omitempty" validate:"valueType"`
//ini,json,text,yaml,properties,xml
+ Priority int `json:"priority,omitempty"
yaml:"priority,omitempty"`
//the smaller value,the higher priority
Checker string `json:"check,omitempty" yaml:"check,omitempty"
validate:"max=1048576,check"` //python script
CreateRevision int64 `json:"create_revision,omitempty"
bson:"create_revision," yaml:"create_revision,omitempty"`
UpdateRevision int64 `json:"update_revision,omitempty"
bson:"update_revision," yaml:"update_revision,omitempty"`
diff --git a/server/datasource/etcd/history/history_dao.go
b/server/datasource/etcd/history/history_dao.go
index bebc4ea..f1ce04d 100644
--- a/server/datasource/etcd/history/history_dao.go
+++ b/server/datasource/etcd/history/history_dao.go
@@ -21,10 +21,11 @@ import (
"context"
"encoding/json"
- "github.com/apache/servicecomb-kie/server/datasource/auth"
"github.com/go-chassis/openlog"
"github.com/little-cui/etcdadpt"
+ "github.com/apache/servicecomb-kie/server/datasource/auth"
+
"github.com/apache/servicecomb-kie/pkg/model"
"github.com/apache/servicecomb-kie/server/datasource"
"github.com/apache/servicecomb-kie/server/datasource/etcd/key"
@@ -80,7 +81,7 @@ func pagingResult(histories []*model.KVDoc, offset, limit
int64) []*model.KVDoc
return []*model.KVDoc{}
}
- datasource.ReverseByUpdateRev(histories)
+ datasource.ReverseByPriorityAndUpdateRev(histories)
if limit == 0 {
return histories
diff --git a/server/datasource/etcd/kv/kv_dao.go
b/server/datasource/etcd/kv/kv_dao.go
index 6c1745d..84c6958 100644
--- a/server/datasource/etcd/kv/kv_dao.go
+++ b/server/datasource/etcd/kv/kv_dao.go
@@ -23,14 +23,15 @@ import (
"regexp"
"strings"
+ "github.com/go-chassis/cari/sync"
+ "github.com/go-chassis/openlog"
+ "github.com/little-cui/etcdadpt"
+
"github.com/apache/servicecomb-kie/pkg/model"
"github.com/apache/servicecomb-kie/pkg/util"
"github.com/apache/servicecomb-kie/server/datasource"
"github.com/apache/servicecomb-kie/server/datasource/auth"
"github.com/apache/servicecomb-kie/server/datasource/etcd/key"
- "github.com/go-chassis/cari/sync"
- "github.com/go-chassis/openlog"
- "github.com/little-cui/etcdadpt"
)
// Dao operate data in mongodb
@@ -609,7 +610,7 @@ func toRegex(opts datasource.FindOptions) (*regexp.Regexp,
error) {
}
func pagingResult(result *model.KVResponse, opts datasource.FindOptions)
*model.KVResponse {
- datasource.ReverseByUpdateRev(result.Data)
+ datasource.ReverseByPriorityAndUpdateRev(result.Data)
if opts.Limit == 0 {
return result
diff --git a/server/datasource/kv_sort.go b/server/datasource/kv_sort.go
index f181e79..3cae128 100644
--- a/server/datasource/kv_sort.go
+++ b/server/datasource/kv_sort.go
@@ -32,14 +32,17 @@ func (k *KVDocSorter) Len() int {
}
func (k *KVDocSorter) Less(i, j int) bool {
- return k.KVs[i].UpdateRevision > k.KVs[j].UpdateRevision
+ if k.KVs[i].Priority == k.KVs[j].Priority {
+ return k.KVs[i].UpdateRevision > k.KVs[j].UpdateRevision
+ }
+ return k.KVs[i].Priority > k.KVs[j].Priority
}
func (k *KVDocSorter) Swap(i, j int) {
k.KVs[i], k.KVs[j] = k.KVs[j], k.KVs[i]
}
-func ReverseByUpdateRev(kvs []*model.KVDoc) {
+func ReverseByPriorityAndUpdateRev(kvs []*model.KVDoc) {
sorter := &KVDocSorter{KVs: kvs}
sort.Sort(sorter)
}