Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: remove issue and pipeline caches from store (#18520)
Danny Xu8c828cd11565
diff --git a/backend/store/issue.go b/backend/store/issue.goindex 1fb8651b2c..8630ef82b7 100644--- a/backend/store/issue.go+++ b/backend/store/issue.go@@ -99,12 +99,6 @@ type FindIssueMessage struct {// GetIssue gets issue by issue UID.func (s *Store) GetIssue(ctx context.Context, find *FindIssueMessage) (*IssueMessage, error) {- if find.UID != nil {- if v, ok := s.issueCache.Get(*find.UID); ok && s.enableCache {- return v, nil- }- }-issues, err := s.ListIssues(ctx, find)if err != nil {return nil, err@@ -115,10 +109,7 @@ func (s *Store) GetIssue(ctx context.Context, find *FindIssueMessage) (*IssueMesif len(issues) > 1 {return nil, &common.Error{Code: common.Conflict, Err: errors.Errorf("found %d issues with find %#v, expect 1", len(issues), find)}}- issue := issues[0]-- s.issueCache.Add(issue.UID, issue)- return issue, nil+ return issues[0], nil}// CreateIssue creates a new issue.@@ -243,8 +234,6 @@ func (s *Store) UpdateIssue(ctx context.Context, uid int, patch *UpdateIssueMessreturn nil, err}- // Invalid the cache and read the value again.- s.issueCache.Remove(uid)return s.GetIssue(ctx, &FindIssueMessage{UID: &uid})}@@ -454,8 +443,6 @@ func (s *Store) ListIssues(ctx context.Context, find *FindIssueMessage) ([]*Issureturn nil, err}issue.Project = project-- s.issueCache.Add(issue.UID, issue)}return issues, nil@@ -463,23 +450,12 @@ func (s *Store) ListIssues(ctx context.Context, find *FindIssueMessage) ([]*Issu// BatchUpdateIssueStatuses updates the status of multiple issues.func (s *Store) BatchUpdateIssueStatuses(ctx context.Context, issueUIDs []int, status storepb.Issue_Status) error {- // First get the pipeline IDs for cache invalidation- selectQuery := qb.Q().Space(`- SELECT issue.id, plan.pipeline_id- FROM issue- LEFT JOIN plan ON issue.plan_id = plan.id- WHERE issue.id = ANY(?)- `, issueUIDs)- selectSQL, selectArgs, err := selectQuery.ToSQL()+ // Update the statuses+ updateQuery := qb.Q().Space("UPDATE issue SET status = ? WHERE id = ANY(?)", status.String(), issueUIDs)+ updateSQL, updateArgs, err := updateQuery.ToSQL()if err != nil {- return errors.Wrapf(err, "failed to build select sql")- }-- type issueInfo struct {- id int- pipelineUID *int+ return errors.Wrapf(err, "failed to build update sql")}- var infos []issueInfotx, err := s.GetDB().BeginTx(ctx, nil)if err != nil {@@ -487,29 +463,6 @@ func (s *Store) BatchUpdateIssueStatuses(ctx context.Context, issueUIDs []int, s}defer tx.Rollback()- rows, err := tx.QueryContext(ctx, selectSQL, selectArgs...)- if err != nil {- return errors.Wrapf(err, "failed to query")- }- defer rows.Close()- for rows.Next() {- var info issueInfo- if err := rows.Scan(&info.id, &info.pipelineUID); err != nil {- return errors.Wrapf(err, "failed to scan")- }- infos = append(infos, info)- }- if err := rows.Err(); err != nil {- return errors.Wrapf(err, "failed to scan issues")- }-- // Update the statuses- updateQuery := qb.Q().Space("UPDATE issue SET status = ? WHERE id = ANY(?)", status.String(), issueUIDs)- updateSQL, updateArgs, err := updateQuery.ToSQL()- if err != nil {- return errors.Wrapf(err, "failed to build update sql")- }-if _, err := tx.ExecContext(ctx, updateSQL, updateArgs...); err != nil {return errors.Wrapf(err, "failed to update")}@@ -517,12 +470,6 @@ func (s *Store) BatchUpdateIssueStatuses(ctx context.Context, issueUIDs []int, sif err := tx.Commit(); err != nil {return errors.Wrapf(err, "failed to commit")}-- // Invalidate caches- for _, info := range infos {- s.issueCache.Remove(info.id)- }-return nil}diff --git a/backend/store/pipeline.go b/backend/store/pipeline.goindex bec20c3c17..961ba56bdd 100644--- a/backend/store/pipeline.go+++ b/backend/store/pipeline.go@@ -205,11 +205,6 @@ func (*Store) createPipeline(ctx context.Context, txn *sql.Tx, create *PipelineM// GetPipeline gets the pipeline.func (s *Store) GetPipeline(ctx context.Context, find *PipelineFind) (*PipelineMessage, error) {- if find.ID != nil {- if v, ok := s.pipelineCache.Get(*find.ID); ok && s.enableCache {- return v, nil- }- }pipelines, err := s.ListPipelines(ctx, find)if err != nil {return nil, err@@ -310,10 +305,6 @@ func (s *Store) ListPipelines(ctx context.Context, find *PipelineFind) ([]*Pipelif err := tx.Commit(); err != nil {return nil, err}-- for _, pipeline := range pipelines {- s.pipelineCache.Add(pipeline.ID, pipeline)- }return pipelines, nil}diff --git a/backend/store/principal.go b/backend/store/principal.goindex 597c7dbf7e..7d93ac5939 100644--- a/backend/store/principal.go+++ b/backend/store/principal.go@@ -537,45 +537,6 @@ func (s *Store) UpdateUser(ctx context.Context, currentUser *UserMessage, patchfunc (s *Store) UpdateUserEmail(ctx context.Context, user *UserMessage, newEmail string) (*UserMessage, error) {newEmail = strings.ToLower(newEmail)- // Fetch affected issues for cache invalidation later.- // We need to fetch both issue ID and pipeline ID (via plan).- // We do this before the transaction/update because finding by old creator is straightforward.- issueQuery := qb.Q().Space(`- SELECT- issue.id,- plan.pipeline_id- FROM issue- LEFT JOIN plan ON issue.plan_id = plan.id- WHERE issue.creator = ?- `, user.Email)- issueSQL, issueArgs, err := issueQuery.ToSQL()- if err != nil {- return nil, errors.Wrapf(err, "failed to build select issue sql")- }-- rows, err := s.GetDB().QueryContext(ctx, issueSQL, issueArgs...)- if err != nil {- return nil, errors.Wrapf(err, "failed to query affected issues")- }- defer rows.Close()-- type issueInvalidation struct {- id int- pipelineUID *int- }- var issuesToInvalidate []issueInvalidation- for rows.Next() {- var info issueInvalidation- if err := rows.Scan(&info.id, &info.pipelineUID); err != nil {- return nil, errors.Wrapf(err, "failed to scan issue info")- }- issuesToInvalidate = append(issuesToInvalidate, info)- }- if err := rows.Err(); err != nil {- return nil, errors.Wrapf(err, "failed to scan issue rows")- }- rows.Close()-tx, err := s.GetDB().BeginTx(ctx, nil)if err != nil {return nil, err@@ -705,7 +666,7 @@ func (s *Store) UpdateUserEmail(ctx context.Context, user *UserMessage, newEmail)RETURNING resource_type, resource, type`- rows, err = tx.QueryContext(ctx, iamPolicySQL, oldUserRef, newUserRef, storepb.Policy_IAM.String())+ rows, err := tx.QueryContext(ctx, iamPolicySQL, oldUserRef, newUserRef, storepb.Policy_IAM.String())if err != nil {return nil, errors.Wrapf(err, "failed to update IAM policies")}@@ -898,11 +859,6 @@ func (s *Store) UpdateUserEmail(ctx context.Context, user *UserMessage, newEmail// 6. Update cachess.userEmailCache.Remove(user.Email)- // Invalidate issue caches- for _, issue := range issuesToInvalidate {- s.issueCache.Remove(issue.id)- }-// Invalidate policy cache for updated policiesfor _, p := range invalidatedPolicies {s.policyCache.Remove(getPolicyCacheKey(p.ResourceType, p.Resource, p.Type))diff --git a/backend/store/store.go b/backend/store/store.goindex 6edcfe5684..8a6b4c9020 100644--- a/backend/store/store.go+++ b/backend/store/store.go@@ -24,8 +24,6 @@ type Store struct {databaseCache *lru.Cache[string, *DatabaseMessage]projectCache *lru.Cache[string, *ProjectMessage]policyCache *lru.Cache[string, *PolicyMessage]- issueCache *lru.Cache[int, *IssueMessage]- pipelineCache *lru.Cache[int, *PipelineMessage]settingCache *lru.Cache[storepb.SettingName, *SettingMessage]rolesCache *lru.Cache[string, *RoleMessage]groupCache *lru.Cache[string, *GroupMessage]@@ -59,14 +57,6 @@ func New(ctx context.Context, pgURL string, enableCache bool) (*Store, error) {if err != nil {return nil, err}- issueCache, err := lru.New[int, *IssueMessage](256)- if err != nil {- return nil, err- }- pipelineCache, err := lru.New[int, *PipelineMessage](256)- if err != nil {- return nil, err- }settingCache, err := lru.New[storepb.SettingName, *SettingMessage](64)if err != nil {return nil, err@@ -108,8 +98,6 @@ func New(ctx context.Context, pgURL string, enableCache bool) (*Store, error) {databaseCache: databaseCache,projectCache: projectCache,policyCache: policyCache,- issueCache: issueCache,- pipelineCache: pipelineCache,settingCache: settingCache,rolesCache: rolesCache,sheetMetadataCache: sheetMetadataCache,diff --git a/backend/store/task_run.go b/backend/store/task_run.goindex 36aff65fd0..28dcd37e94 100644--- a/backend/store/task_run.go+++ b/backend/store/task_run.go@@ -214,10 +214,6 @@ func (s *Store) UpdateTaskRunStatus(ctx context.Context, patch *TaskRunStatusPatif err := tx.Commit(); err != nil {return nil, errors.Wrapf(err, "failed to commit tx")}-- // Invalidate pipeline cache since UpdatedAt depends on task run updates- s.pipelineCache.Remove(pipelineID)-return taskRun, nil}@@ -239,10 +235,6 @@ func (s *Store) UpdateTaskRunStartAt(ctx context.Context, taskRunID int) error {if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan(&pipelineID); err != nil {return errors.Wrapf(err, "failed to update task run start at")}-- // Invalidate pipeline cache since UpdatedAt depends on task run updates- s.pipelineCache.Remove(pipelineID)-return nil}@@ -369,57 +361,19 @@ func (s *Store) BatchCancelTaskRuns(ctx context.Context, taskRunIDs []int) errorif len(taskRunIDs) == 0 {return nil}-- // Get affected pipeline IDs for cache invalidationq := qb.Q().Space(`- SELECT DISTINCT task.pipeline_id- FROM task_run- JOIN task ON task.id = task_run.task_id- WHERE task_run.id = ANY(?)- `, taskRunIDs)-- query, args, err := q.ToSQL()- if err != nil {- return errors.Wrapf(err, "failed to build sql")- }-- rows, err := s.GetDB().QueryContext(ctx, query, args...)- if err != nil {- return errors.Wrapf(err, "failed to get pipeline IDs")- }- defer rows.Close()-- var pipelineIDs []int- for rows.Next() {- var pipelineID int- if err := rows.Scan(&pipelineID); err != nil {- return errors.Wrapf(err, "failed to scan pipeline ID")- }- pipelineIDs = append(pipelineIDs, pipelineID)- }- if err := rows.Err(); err != nil {- return errors.Wrapf(err, "failed to iterate pipeline IDs")- }-- q2 := qb.Q().Space(`UPDATE task_runSET status = ?, updated_at = now()WHERE id = ANY(?)`, storepb.TaskRun_CANCELED.String(), taskRunIDs)- query2, args2, err := q2.ToSQL()+ query, args, err := q.ToSQL()if err != nil {return errors.Wrapf(err, "failed to build sql")}- if _, err := s.GetDB().ExecContext(ctx, query2, args2...); err != nil {+ if _, err := s.GetDB().ExecContext(ctx, query, args...); err != nil {return err}-- // Invalidate pipeline caches since UpdatedAt depends on task run updates- for _, pipelineID := range pipelineIDs {- s.pipelineCache.Remove(pipelineID)- }-return nil}