Skip to content

Commit

Permalink
make Selector a pointer type
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Sep 24, 2024
1 parent c54fff0 commit b4ec701
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
6 changes: 3 additions & 3 deletions internal/datasourcev2/polling_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type PollingResponse struct {
events []fdv2proto.Event
cached bool
intent fdv2proto.IntentCode
selector fdv2proto.Selector
selector *fdv2proto.Selector
}

func (p *PollingResponse) Events() []fdv2proto.Event {
Expand All @@ -37,7 +37,7 @@ func (p *PollingResponse) Intent() fdv2proto.IntentCode {
return p.intent
}

func (p *PollingResponse) Selector() fdv2proto.Selector {
func (p *PollingResponse) Selector() *fdv2proto.Selector {
return p.selector
}

Expand All @@ -47,7 +47,7 @@ func NewCachedPollingResponse() *PollingResponse {
}
}

func NewPollingResponse(intent fdv2proto.IntentCode, events []fdv2proto.Event, selector fdv2proto.Selector) *PollingResponse {
func NewPollingResponse(intent fdv2proto.IntentCode, events []fdv2proto.Event, selector *fdv2proto.Selector) *PollingResponse {
return &PollingResponse{
events: events,
intent: intent,
Expand Down
10 changes: 5 additions & 5 deletions internal/datasystem/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Store struct {
active subsystems.ReadOnlyStore

// Identifies the current data.
selector fdv2proto.Selector
selector *fdv2proto.Selector

mu sync.RWMutex

Expand Down Expand Up @@ -121,7 +121,7 @@ func (s *Store) WithPersistence(persistent subsystems.DataStore, mode subsystems
}

// Selector returns the current selector.
func (s *Store) Selector() fdv2proto.Selector {
func (s *Store) Selector() *fdv2proto.Selector {
s.mu.RLock()
defer s.mu.RUnlock()
return s.selector
Expand All @@ -137,12 +137,12 @@ func (s *Store) Close() error {
return nil
}

func (s *Store) SetBasis(events []fdv2proto.Event, selector fdv2proto.Selector, persist bool) error {
func (s *Store) SetBasis(events []fdv2proto.Event, selector *fdv2proto.Selector, persist bool) error {
collections := fdv2proto.ToStorableItems(events)
return s.init(collections, selector, persist)
}

func (s *Store) init(allData []ldstoretypes.Collection, selector fdv2proto.Selector, persist bool) error {
func (s *Store) init(allData []ldstoretypes.Collection, selector *fdv2proto.Selector, persist bool) error {
s.mu.Lock()
defer s.mu.Unlock()

Expand All @@ -164,7 +164,7 @@ func (s *Store) shouldPersist() bool {
return s.persist && s.persistentStore.writable()
}

func (s *Store) ApplyDelta(events []fdv2proto.Event, selector fdv2proto.Selector, persist bool) error {
func (s *Store) ApplyDelta(events []fdv2proto.Event, selector *fdv2proto.Selector, persist bool) error {
collections := fdv2proto.ToStorableItems(events)

s.mu.Lock()
Expand Down
2 changes: 1 addition & 1 deletion internal/datasystem/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestStore_NoPersistence_MemoryStore_IsInitialized(t *testing.T) {
none := fdv2proto.NoSelector()
tests := []struct {
name string
selector fdv2proto.Selector
selector *fdv2proto.Selector
persist bool
}{
{"with selector, persist", v1, true},
Expand Down
21 changes: 8 additions & 13 deletions internal/fdv2proto/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,24 @@ package fdv2proto
type Selector struct {

Check failure on line 3 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / ldotel Linux, Go 1.22

exported: exported type Selector should have comment or be unexported (revive)

Check failure on line 3 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / Linux, Go 1.22 / Unit Tests and Coverage

exported: exported type Selector should have comment or be unexported (revive)

Check failure on line 3 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / Linux, Go 1.18 / Unit Tests and Coverage

exported: exported type Selector should have comment or be unexported (revive)

Check failure on line 3 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / Linux, Go 1.23 / Unit Tests and Coverage

exported: exported type Selector should have comment or be unexported (revive)

Check failure on line 3 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / ldotel Linux, Go 1.23

exported: exported type Selector should have comment or be unexported (revive)

Check failure on line 3 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / ldotel Linux, Go 1.18

exported: exported type Selector should have comment or be unexported (revive)
state string
version int
set bool
}

func NoSelector() Selector {
return Selector{set: false}
func NoSelector() *Selector {

Check failure on line 8 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / ldotel Linux, Go 1.22

exported: exported function NoSelector should have comment or be unexported (revive)

Check failure on line 8 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / Linux, Go 1.22 / Unit Tests and Coverage

exported: exported function NoSelector should have comment or be unexported (revive)

Check failure on line 8 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / Linux, Go 1.18 / Unit Tests and Coverage

exported: exported function NoSelector should have comment or be unexported (revive)

Check failure on line 8 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / Linux, Go 1.23 / Unit Tests and Coverage

exported: exported function NoSelector should have comment or be unexported (revive)

Check failure on line 8 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / ldotel Linux, Go 1.23

exported: exported function NoSelector should have comment or be unexported (revive)

Check failure on line 8 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / ldotel Linux, Go 1.18

exported: exported function NoSelector should have comment or be unexported (revive)
return nil
}

func NewSelector(state string, version int) Selector {
return Selector{state: state, version: version, set: true}
func NewSelector(state string, version int) *Selector {

Check failure on line 12 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / ldotel Linux, Go 1.22

exported: exported function NewSelector should have comment or be unexported (revive)

Check failure on line 12 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / Linux, Go 1.22 / Unit Tests and Coverage

exported: exported function NewSelector should have comment or be unexported (revive)

Check failure on line 12 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / Linux, Go 1.18 / Unit Tests and Coverage

exported: exported function NewSelector should have comment or be unexported (revive)

Check failure on line 12 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / ldotel Linux, Go 1.18

exported: exported function NewSelector should have comment or be unexported (revive)
return &Selector{state: state, version: version}
}

func (s Selector) IsSet() bool {
return s.set
func (s *Selector) IsSet() bool {

Check failure on line 16 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / ldotel Linux, Go 1.22

exported: exported method Selector.IsSet should have comment or be unexported (revive)

Check failure on line 16 in internal/fdv2proto/selector.go

View workflow job for this annotation

GitHub Actions / Linux, Go 1.18 / Unit Tests and Coverage

exported: exported method Selector.IsSet should have comment or be unexported (revive)
return s != nil
}

func (s Selector) State() string {
func (s *Selector) State() string {
return s.state
}

func (s Selector) Version() int {
func (s *Selector) Version() int {
return s.version
}

func (s Selector) Get() (string, int, bool) {
return s.state, s.version, s.set
}
4 changes: 2 additions & 2 deletions internal/sharedtest/mocks/mock_data_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewMockDataDestination(realStore subsystems.DataStore) *MockDataDestination
}

// SetBasis in this test implementation, delegates to d.DataStore.CapturedUpdates.
func (d *MockDataDestination) SetBasis(events []fdv2proto.Event, selector fdv2proto.Selector, persist bool) error {
func (d *MockDataDestination) SetBasis(events []fdv2proto.Event, _ *fdv2proto.Selector, _ bool) error {
// For now, the selector is ignored. When the data sources start making use of it, it should be
// stored so that assertions can be made.

Expand All @@ -54,7 +54,7 @@ func (d *MockDataDestination) SetBasis(events []fdv2proto.Event, selector fdv2pr
return d.DataStore.Init(collections)
}

func (d *MockDataDestination) ApplyDelta(events []fdv2proto.Event, selector fdv2proto.Selector, persist bool) error {
func (d *MockDataDestination) ApplyDelta(events []fdv2proto.Event, _ *fdv2proto.Selector, _ bool) error {
// For now, the selector is ignored. When the data sources start making use of it, it should be
// stored so that assertions can be made.

Expand Down
4 changes: 2 additions & 2 deletions subsystems/data_destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type DataDestination interface {
//
// If persist is true, it indicates that the data should be propagated to any connected persistent
// store.
SetBasis(events []fdv2proto.Event, selector fdv2proto.Selector, persist bool) error
SetBasis(events []fdv2proto.Event, selector *fdv2proto.Selector, persist bool) error

// ApplyDelta applies a set of changes to an existing basis. This operation should be atomic with
// respect to any other operations that modify the store.
Expand All @@ -28,5 +28,5 @@ type DataDestination interface {
//
// If persist is true, it indicates that the changes should be propagated to any connected persistent
// store.
ApplyDelta(events []fdv2proto.Event, selector fdv2proto.Selector, persist bool) error
ApplyDelta(events []fdv2proto.Event, selector *fdv2proto.Selector, persist bool) error
}

0 comments on commit b4ec701

Please sign in to comment.