Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: risks cache (#5284)

p0ny348bfc5e8c07
diff --git a/backend/store/risk.go b/backend/store/risk.go
index 4efafeecf0..53d80e9127 100644
--- a/backend/store/risk.go
+++ b/backend/store/risk.go
@@ -101,10 +101,8 @@ func (s *Store) GetRisk(ctx context.Context, id int64) (*RiskMessage, error) {
// ListRisks lists risks.
func (s *Store) ListRisks(ctx context.Context) ([]*RiskMessage, error) {
- if cached := s.risksCache.Load(); cached != nil {
- if risks, ok := cached.([]*RiskMessage); ok {
- return risks, nil
- }
+ if risks, ok := s.risksCache.Load(0); ok {
+ return risks.([]*RiskMessage), nil
}
query := `
@@ -163,7 +161,7 @@ func (s *Store) ListRisks(ctx context.Context) ([]*RiskMessage, error) {
return nil, errors.Wrap(err, "failed to commit")
}
- s.risksCache.Store(risks)
+ s.risksCache.Store(0, risks)
return risks, nil
}
@@ -201,7 +199,7 @@ func (s *Store) CreateRisk(ctx context.Context, risk *RiskMessage, creatorID int
return nil, errors.Wrap(err, "failed to commit")
}
- s.risksCache.Store(([]*RiskMessage)(nil))
+ s.risksCache.Delete(0)
return &RiskMessage{
ID: id,
Source: risk.Source,
@@ -255,6 +253,6 @@ func (s *Store) UpdateRisk(ctx context.Context, patch *UpdateRiskMessage, id int
return nil, errors.Wrap(err, "failed to commit")
}
- s.risksCache.Store(([]*RiskMessage)(nil))
+ s.risksCache.Delete(0)
return s.GetRisk(ctx, id)
}
diff --git a/backend/store/store.go b/backend/store/store.go
index 599ecb4cc3..c4356f14a4 100644
--- a/backend/store/store.go
+++ b/backend/store/store.go
@@ -4,7 +4,6 @@ package store
import (
"fmt"
"sync"
- "sync/atomic"
api "github.com/bytebase/bytebase/backend/legacyapi"
)
@@ -13,26 +12,26 @@ import (
type Store struct {
db *DB
- userIDCache sync.Map // map[int]*UserMessage
- environmentCache sync.Map // map[string]*EnvironmentMessage
- environmentIDCache sync.Map // map[int]*EnvironmentMessage
- instanceCache sync.Map // map[string]*InstanceMessage
- instanceIDCache sync.Map // map[int]*InstanceMessage
- databaseCache sync.Map // map[string]*DatabaseMessage
- databaseIDCache sync.Map // map[int]*DatabaseMessage
- projectCache sync.Map // map[string]*ProjectMessage
- projectIDCache sync.Map // map[int]*ProjectMessage
- projectPolicyCache sync.Map // map[string]*IAMPolicyMessage
- projectIDPolicyCache sync.Map // map[int]*IAMPolicyMessage
- policyCache sync.Map // map[string]*PolicyMessage
- issueCache sync.Map // map[int]*IssueMessage
- issueByPipelineCache sync.Map // map[int]*IssueMessage
- pipelineCache sync.Map // map[int]*PipelineMessage
- dbSchemaCache sync.Map // map[int]*DBSchema
- settingCache sync.Map // map[string]*SettingMessage
- idpCache sync.Map // map[string]*IdentityProvider
- projectIDDeploymentConfigCache sync.Map // map[int]*DeploymentConfigMessage
- risksCache atomic.Value // []*RiskMessage
+ userIDCache sync.Map // map[int]*UserMessage
+ environmentCache sync.Map // map[string]*EnvironmentMessage
+ environmentIDCache sync.Map // map[int]*EnvironmentMessage
+ instanceCache sync.Map // map[string]*InstanceMessage
+ instanceIDCache sync.Map // map[int]*InstanceMessage
+ databaseCache sync.Map // map[string]*DatabaseMessage
+ databaseIDCache sync.Map // map[int]*DatabaseMessage
+ projectCache sync.Map // map[string]*ProjectMessage
+ projectIDCache sync.Map // map[int]*ProjectMessage
+ projectPolicyCache sync.Map // map[string]*IAMPolicyMessage
+ projectIDPolicyCache sync.Map // map[int]*IAMPolicyMessage
+ policyCache sync.Map // map[string]*PolicyMessage
+ issueCache sync.Map // map[int]*IssueMessage
+ issueByPipelineCache sync.Map // map[int]*IssueMessage
+ pipelineCache sync.Map // map[int]*PipelineMessage
+ dbSchemaCache sync.Map // map[int]*DBSchema
+ settingCache sync.Map // map[string]*SettingMessage
+ idpCache sync.Map // map[string]*IdentityProvider
+ projectIDDeploymentConfigCache sync.Map // map[int]*DeploymentConfigMessage
+ risksCache sync.Map // []*RiskMessage, use 0 as the key
}
// New creates a new instance of Store.