mirror of
https://github.com/rancher/steve.git
synced 2025-09-15 23:08:26 +00:00
Pass the listOptions struct by reference to avoid copying.
We never update the ListOptions struct once it's created so there's no need to pass it by value. This might be a near-useless optimization...
This commit is contained in:
@@ -30,7 +30,7 @@ type Informer struct {
|
||||
}
|
||||
|
||||
type ByOptionsLister interface {
|
||||
ListByOptions(ctx context.Context, lo sqltypes.ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, string, error)
|
||||
ListByOptions(ctx context.Context, lo *sqltypes.ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, string, error)
|
||||
}
|
||||
|
||||
// this is set to a var so that it can be overridden by test code for mocking purposes
|
||||
@@ -66,7 +66,7 @@ func NewInformer(ctx context.Context, client dynamic.ResourceInterface, fields [
|
||||
// copy of the known state of all objects (in an Indexer).
|
||||
// The resync period option here is passed from Informer to Reflector to periodically (re)-push all known
|
||||
// objects to the DeltaFIFO. That causes the periodic (re-)firing all registered handlers.
|
||||
// sqltypes.In this case we are not registering any handlers to this particular informer, so re-syncing is a no-op.
|
||||
// In this case we are not registering any handlers to this particular informer, so re-syncing is a no-op.
|
||||
// We therefore just disable it right away.
|
||||
resyncPeriod := time.Duration(0)
|
||||
|
||||
@@ -103,7 +103,7 @@ func NewInformer(ctx context.Context, client dynamic.ResourceInterface, fields [
|
||||
// - the total number of resources (returned list might be a subset depending on pagination options in lo)
|
||||
// - a continue token, if there are more pages after the returned one
|
||||
// - an error instead of all of the above if anything went wrong
|
||||
func (i *Informer) ListByOptions(ctx context.Context, lo sqltypes.ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, string, error) {
|
||||
func (i *Informer) ListByOptions(ctx context.Context, lo *sqltypes.ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, string, error) {
|
||||
return i.ByOptionsLister.ListByOptions(ctx, lo, partitions, namespace)
|
||||
}
|
||||
|
||||
|
@@ -43,7 +43,7 @@ func (m *MockByOptionsLister) EXPECT() *MockByOptionsListerMockRecorder {
|
||||
}
|
||||
|
||||
// ListByOptions mocks base method.
|
||||
func (m *MockByOptionsLister) ListByOptions(arg0 context.Context, arg1 sqltypes.ListOptions, arg2 []partition.Partition, arg3 string) (*unstructured.UnstructuredList, int, string, error) {
|
||||
func (m *MockByOptionsLister) ListByOptions(arg0 context.Context, arg1 *sqltypes.ListOptions, arg2 []partition.Partition, arg3 string) (*unstructured.UnstructuredList, int, string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "ListByOptions", arg0, arg1, arg2, arg3)
|
||||
ret0, _ := ret[0].(*unstructured.UnstructuredList)
|
||||
|
@@ -325,8 +325,8 @@ func TestInformerListByOptions(t *testing.T) {
|
||||
}
|
||||
expectedTotal := len(expectedList.Items)
|
||||
expectedContinueToken := "123"
|
||||
indexer.EXPECT().ListByOptions(context.Background(), lo, partitions, ns).Return(expectedList, expectedTotal, expectedContinueToken, nil)
|
||||
list, total, continueToken, err := informer.ListByOptions(context.Background(), lo, partitions, ns)
|
||||
indexer.EXPECT().ListByOptions(context.Background(), &lo, partitions, ns).Return(expectedList, expectedTotal, expectedContinueToken, nil)
|
||||
list, total, continueToken, err := informer.ListByOptions(context.Background(), &lo, partitions, ns)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expectedList, list)
|
||||
assert.Equal(t, len(expectedList.Items), total)
|
||||
@@ -340,8 +340,8 @@ func TestInformerListByOptions(t *testing.T) {
|
||||
lo := sqltypes.ListOptions{}
|
||||
var partitions []partition.Partition
|
||||
ns := "somens"
|
||||
indexer.EXPECT().ListByOptions(context.Background(), lo, partitions, ns).Return(nil, 0, "", fmt.Errorf("error"))
|
||||
_, _, _, err := informer.ListByOptions(context.Background(), lo, partitions, ns)
|
||||
indexer.EXPECT().ListByOptions(context.Background(), &lo, partitions, ns).Return(nil, 0, "", fmt.Errorf("error"))
|
||||
_, _, _, err := informer.ListByOptions(context.Background(), &lo, partitions, ns)
|
||||
assert.NotNil(t, err)
|
||||
}})
|
||||
t.Parallel()
|
||||
|
@@ -248,7 +248,7 @@ func (l *ListOptionIndexer) deleteLabels(key string, tx transaction.Client) erro
|
||||
// - the total number of resources (returned list might be a subset depending on pagination options in lo)
|
||||
// - a continue token, if there are more pages after the returned one
|
||||
// - an error instead of all of the above if anything went wrong
|
||||
func (l *ListOptionIndexer) ListByOptions(ctx context.Context, lo sqltypes.ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, string, error) {
|
||||
func (l *ListOptionIndexer) ListByOptions(ctx context.Context, lo *sqltypes.ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, string, error) {
|
||||
queryInfo, err := l.constructQuery(lo, partitions, namespace, db.Sanitize(l.GetName()))
|
||||
if err != nil {
|
||||
return nil, 0, "", err
|
||||
@@ -267,8 +267,8 @@ type QueryInfo struct {
|
||||
offset int
|
||||
}
|
||||
|
||||
func (l *ListOptionIndexer) constructQuery(lo sqltypes.ListOptions, partitions []partition.Partition, namespace string, dbName string) (*QueryInfo, error) {
|
||||
ensureSortLabelsAreSelected(&lo)
|
||||
func (l *ListOptionIndexer) constructQuery(lo *sqltypes.ListOptions, partitions []partition.Partition, namespace string, dbName string) (*QueryInfo, error) {
|
||||
ensureSortLabelsAreSelected(lo)
|
||||
queryInfo := &QueryInfo{}
|
||||
queryUsesLabels := hasLabelFilter(lo.Filters)
|
||||
joinTableIndexByLabelName := make(map[string]int)
|
||||
|
@@ -978,7 +978,7 @@ func TestListByOptions(t *testing.T) {
|
||||
if len(test.extraIndexedFields) > 0 {
|
||||
lii.indexedFields = append(lii.indexedFields, test.extraIndexedFields...)
|
||||
}
|
||||
queryInfo, err := lii.constructQuery(test.listOptions, test.partitions, test.ns, "something")
|
||||
queryInfo, err := lii.constructQuery(&test.listOptions, test.partitions, test.ns, "something")
|
||||
if test.expectedErr != nil {
|
||||
assert.Equal(t, test.expectedErr, err)
|
||||
return
|
||||
@@ -1667,7 +1667,7 @@ func TestConstructQuery(t *testing.T) {
|
||||
Indexer: i,
|
||||
indexedFields: []string{"metadata.queryField1", "status.queryField2"},
|
||||
}
|
||||
queryInfo, err := lii.constructQuery(test.listOptions, test.partitions, test.ns, "something")
|
||||
queryInfo, err := lii.constructQuery(&test.listOptions, test.partitions, test.ns, "something")
|
||||
if test.expectedErr != nil {
|
||||
assert.Equal(t, test.expectedErr, err)
|
||||
return
|
||||
|
@@ -284,7 +284,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
partitions := []partition.Partition{defaultPartition}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
cfgMaps, total, continueToken, err := cache.ListByOptions(ctx, options, partitions, testNamespace)
|
||||
cfgMaps, total, continueToken, err := cache.ListByOptions(ctx, &options, partitions, testNamespace)
|
||||
i.Require().NoError(err)
|
||||
// since there's no additional pages, the continue token should be empty
|
||||
i.Require().Equal("", continueToken)
|
||||
@@ -338,7 +338,7 @@ func (i *IntegrationSuite) waitForCacheReady(readyResourceNames []string, namesp
|
||||
partitions := []partition.Partition{defaultPartition}
|
||||
cacheCtx, cacheCancel := context.WithTimeout(ctx, time.Second*5)
|
||||
defer cacheCancel()
|
||||
currentResources, total, _, err := cache.ListByOptions(cacheCtx, options, partitions, namespace)
|
||||
currentResources, total, _, err := cache.ListByOptions(cacheCtx, &options, partitions, namespace)
|
||||
if err != nil {
|
||||
// note that we don't return the error since that would stop the polling
|
||||
return false, nil
|
||||
|
Reference in New Issue
Block a user