This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/answer.git

commit 9f8cab56267f2f9e19eaa393e1c4be98e0090e19
Author: Sonui <m...@sonui.cn>
AuthorDate: Sat Mar 1 11:56:32 2025 +0800

    perf(plugin): remove unnecessary KV storage checks
---
 plugin/kv_storage.go | 33 ---------------------------------
 1 file changed, 33 deletions(-)

diff --git a/plugin/kv_storage.go b/plugin/kv_storage.go
index b4d940b8..a3ab46d0 100644
--- a/plugin/kv_storage.go
+++ b/plugin/kv_storage.go
@@ -48,16 +48,6 @@ type KVOperator struct {
        pluginSlugName string
 }
 
-func (kv *KVOperator) checkDB() error {
-       if kv.data == nil {
-               return ErrKVDataNotInitialized
-       }
-       if kv.data.DB == nil {
-               return ErrKVDBNotInitialized
-       }
-       return nil
-}
-
 func (kv *KVOperator) getSession(ctx context.Context) (session *xorm.Session, 
close func()) {
        if kv.session != nil {
                session = kv.session
@@ -88,9 +78,6 @@ func (kv *KVOperator) getCacheKey(group, key string) string {
 
 func (kv *KVOperator) Get(ctx context.Context, group, key string) (string, 
error) {
        // validate
-       if err := kv.checkDB(); err != nil {
-               return "", err
-       }
        if key == "" {
                return "", ErrKVKeyEmpty
        }
@@ -127,10 +114,6 @@ func (kv *KVOperator) Get(ctx context.Context, group, key 
string) (string, error
 }
 
 func (kv *KVOperator) Set(ctx context.Context, group, key, value string) error 
{
-       if err := kv.checkDB(); err != nil {
-               return err
-       }
-
        if key == "" {
                return ErrKVKeyEmpty
        }
@@ -168,10 +151,6 @@ func (kv *KVOperator) Set(ctx context.Context, group, key, 
value string) error {
 }
 
 func (kv *KVOperator) Del(ctx context.Context, group, key string) error {
-       if err := kv.checkDB(); err != nil {
-               return err
-       }
-
        if key == "" && group == "" {
                return ErrKVKeyAndGroupEmpty
        }
@@ -216,10 +195,6 @@ func (kv *KVOperator) cleanCache(ctx context.Context, 
group, key string) {
 }
 
 func (kv *KVOperator) GetByGroup(ctx context.Context, group string, page, 
pageSize int) (map[string]string, error) {
-       if err := kv.checkDB(); err != nil {
-               return nil, err
-       }
-
        if group == "" {
                return nil, ErrKVGroupEmpty
        }
@@ -231,10 +206,6 @@ func (kv *KVOperator) GetByGroup(ctx context.Context, 
group string, page, pageSi
                pageSize = 10
        }
 
-       if pageSize > 100 {
-               pageSize = 100
-       }
-
        cacheKey := kv.getCacheKey(group, "")
        if value, exist, err := kv.data.Cache.GetString(ctx, cacheKey); err == 
nil && exist {
                result := make(map[string]string)
@@ -271,10 +242,6 @@ func (kv *KVOperator) GetByGroup(ctx context.Context, 
group string, page, pageSi
 }
 
 func (kv *KVOperator) Tx(ctx context.Context, fn func(ctx context.Context, kv 
*KVOperator) error) error {
-       if err := kv.checkDB(); err != nil {
-               return fmt.Errorf("%w: %v", ErrKVTransactionFailed, err)
-       }
-
        var (
                txKv         = kv
                shouldCommit bool

Reply via email to