Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: sheet lru structure (#12271)
Danny Xu982521fe8332
diff --git a/backend/component/sheet/sheet.go b/backend/component/sheet/sheet.goindex 7f2ac0e095..af2f51a388 100644--- a/backend/component/sheet/sheet.go+++ b/backend/component/sheet/sheet.go@@ -5,6 +5,11 @@ import ("io""log/slog""strings"+ "sync"+ "time"++ lru "github.com/hashicorp/golang-lru/v2/expirable"+ "github.com/zeebo/xxh3""github.com/bytebase/bytebase/backend/common""github.com/bytebase/bytebase/backend/plugin/db/mssql"@@ -17,13 +22,17 @@ import (// Manager is the coordinator for all sheets and SQL statements.type Manager struct {- store *store.Store+ sync.Mutex++ store *store.Store+ astCache *lru.LRU[uint64, *Result]}// NewManager creates a new sheet manager.func NewManager(store *store.Store) *Manager {return &Manager{- store: store,+ store: store,+ astCache: lru.NewLRU[uint64, *Result](8, nil, 3*time.Minute),}}@@ -136,3 +145,31 @@ func getSheetCommandsForMSSQL(statement string) []*storepb.SheetCommand {}return sheetCommands}++type Result struct {+ sync.Mutex+ ast any+ err error+}++func (sm *Manager) GetAST(_ storepb.Engine, statement string) (any, error) {+ var result *Result+ hashKey := xxh3.HashString(statement)+ sm.Lock()+ if v, ok := sm.astCache.Get(hashKey); ok {+ result = v+ } else {+ result = &Result{}+ sm.astCache.Add(hashKey, result)+ }+ sm.Unlock()++ result.Lock()+ defer result.Unlock()+ if result.ast != nil {+ return result.ast, result.err+ }+ // TODO(d): do something.+ result.ast = 1+ return result.ast, result.err+}diff --git a/go.mod b/go.modindex 0afa86286d..14673f4fb6 100644--- a/go.mod+++ b/go.mod@@ -78,6 +78,7 @@ require (github.com/vjeantet/ldapserver v1.0.1github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8github.com/xuri/excelize/v2 v2.8.1+ github.com/zeebo/xxh3 v1.0.2go.mongodb.org/mongo-driver v1.15.0go.uber.org/multierr v1.11.0golang.org/x/crypto v0.23.0@@ -175,7 +176,6 @@ require (github.com/vcaesar/cedar v0.20.1 // indirectgithub.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirectgithub.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect- github.com/zeebo/xxh3 v1.0.2 // indirectgo.etcd.io/etcd/api/v3 v3.5.10 // indirectgo.etcd.io/etcd/client/pkg/v3 v3.5.10 // indirectgo.etcd.io/etcd/client/v3 v3.5.10 // indirect