Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert the settings store to use the basestore package #15853

Closed
3 tasks
asdine opened this issue Nov 17, 2020 · 1 comment · Fixed by #17455
Closed
3 tasks

Convert the settings store to use the basestore package #15853

asdine opened this issue Nov 17, 2020 · 1 comment · Fixed by #17455
Assignees
Labels
debt Technical debt. estimate/0.5d

Comments

@asdine
Copy link
Contributor

asdine commented Nov 17, 2020

  • Rename the settings store to settingStore
    type settings struct{}
  • Convert the store to use the basestore package so that it can be instantiated without using the global db connection
    // Store is an abstract Postgres-backed data access layer. Instances of this struct
    // should not be used directly, but should be used compositionally by other stores
    // that implement logic specific to a domain.
    //
    // The following is a minimal example of decorating the base store that preserves
    // the correct behavior of the underlying base store. Note that `With` and `Transact`
    // must be re-defined in the outer layer in order to create a useful return value.
    // Failure to re-define these methods will result in `With` and `Transact` methods that
    // return a modified base store with no methods from the outer layer. All other methods
    // of the base store are available on the outer layer without needing to be re-defined.
    //
    // type SprocketStore struct {
    // *basestore.Store
    // }
    //
    // func NewWithHandle(db dbutil.DB) *SprocketStore {
    // return &SprocketStore{Store: basestore.NewWithHandle(db)}
    // }
    //
    // func (s *SprocketStore) With(other basestore.ShareableStore) *SprocketStore {
    // return &SprocketStore{Store: s.Store.With(other)}
    // }
    //
    // func (s *SprocketStore) Transact(ctx context.Context) (*SprocketStore, error) {
    // txBase, err := s.Store.Transact(ctx)
    // return &SprocketStore{Store: txBase}, nil
    // }

Example: https://github.com/sourcegraph/sourcegraph/blob/main/internal/db/repos.go#L55-L73

  • Make sure the global settings store is usable without initializing it
    // ensureStore instantiates a basestore.Store if necessary, using the dbconn.Global handle.
    // This function ensures access to dbconn happens after the rest of the code or tests have
    // initialized it.
    func (s *RepoStore) ensureStore() {
    s.mu.Lock()
    defer s.mu.Unlock()
    if s.Store == nil {
    s.Store = basestore.NewWithDB(dbconn.Global, sql.TxOptions{})
    }
    }
@asdine asdine added this to the Cloud 2020-11-18 milestone Nov 17, 2020
@asdine asdine self-assigned this Nov 17, 2020
@github-actions
Copy link
Contributor

Heads up @tsenart - the "team/cloud" label was applied to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Technical debt. estimate/0.5d
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant