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

ROX-18155: pg generic store: GetAll #6769

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 0 additions & 12 deletions central/authprovider/datastore/internal/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions central/complianceoperatorintegration/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions central/externalbackups/internal/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions central/group/datastore/internal/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions central/imageintegration/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions central/logimbue/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions central/notifier/datastore/internal/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions central/policy/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions central/policycategory/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions central/policycategoryedge/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions central/serviceidentities/internal/store/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions pkg/search/postgres/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,15 @@ func (s *GenericStore[T, PT]) Walk(ctx context.Context, fn func(obj PT) error) e
}
return nil
}

// GetAll retrieves all objects from the store.
func (s *GenericStore[T, PT]) GetAll(ctx context.Context) ([]PT, error) {
defer s.setPostgresOperationDurationTime(time.Now(), ops.GetAll)

var objs []PT
err := s.Walk(ctx, func(obj PT) error {
objs = append(objs, obj)
return nil
})
return objs, err
}
15 changes: 0 additions & 15 deletions tools/generate-helpers/pg-table-bindings/store.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -727,21 +727,6 @@ func (s *storeImpl) GetIDs(ctx context.Context) ([]{{$singlePK.Type}}, error) {
}
{{- end }}

{{- if .GetAll }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not already done in the cleanup PR, make sure the get-all option is removed from the generator code as well as from the gen.go files that use it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The complete cleanup would impact:

  • the gen.go files next to the stores generated by this pull request
  • tools/generate-helpers/pg-table-bindings/migration.go.tpl (or the file could be removed completely, as well as the gen.go file in the migrator)
  • tools/generate-helpers/pg-table-bindings/store.go.tpl (but I think the current pull request already removes all occurrences)
  • tools/generate-helpers/pg-table-bindings/store_test.go.tpl (to let all stores test the GetAll function)
  • tools/generate-helpers/pg-table-bindings/main.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you think we should expose GetAll method to all stores? I wander what was the reason to have it as optin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// GetAll retrieves all objects from the store.
func(s *storeImpl) GetAll(ctx context.Context) ([]*{{.Type}}, error) {
defer metrics.SetPostgresOperationDurationTime(time.Now(), ops.GetAll, "{{.TrimmedType}}")

var objs []*{{.Type}}
err := s.Walk(ctx, func(obj *{{.Type}}) error {
objs = append(objs, obj)
return nil
})
return objs, err
}
{{- end}}

//// Interface functions - END

//// Used for testing
Expand Down
12 changes: 0 additions & 12 deletions tools/generate-helpers/pg-table-bindings/test/postgres/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.