From 3eb8fb2b2ba872240516c46d8a1860201b67e46f Mon Sep 17 00:00:00 2001 From: Mladen Todorovic Date: Mon, 17 Mar 2025 11:26:53 +0100 Subject: [PATCH 1/2] Add GetByQueryFn Add GetByQueryFn --- .../internal/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../usage/store/postgres/store.go | 1 + .../datastore/internal/store/mocks/store.go | 14 ++++++ .../internal/store/postgres/store.go | 1 + .../alert/datastore/internal/store/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../blob/datastore/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../cluster/store/cluster/postgres/store.go | 1 + .../store/clusterhealth/postgres/store.go | 1 + .../datastore/store/postgres/store.go | 1 + .../internal/store/postgres/domain/store.go | 1 + .../internal/store/postgres/metadata/store.go | 1 + .../internal/store/postgres/results/store.go | 1 + .../v2/benchmarks/store/postgres/store.go | 1 + .../v2/checkresults/store/postgres/store.go | 1 + .../v2/integration/store/postgres/store.go | 1 + .../v2/profiles/store/postgres/store.go | 1 + .../v2/remediations/store/postgres/store.go | 1 + .../v2/report/store/postgres/store.go | 1 + .../v2/rules/store/postgres/store.go | 1 + .../scanconfigstatus/store/postgres/store.go | 1 + .../store/postgres/store.go | 1 + .../v2/scans/store/postgres/store.go | 1 + .../store/postgres/store.go | 1 + .../v2/suites/store/postgres/store.go | 1 + .../datastore/store/postgres/store.go | 1 + .../cluster/datastore/store/postgres/store.go | 1 + .../image/datastore/store/postgres/store.go | 1 + .../v2/datastore/store/postgres/store.go | 1 + .../node/datastore/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../datastore/store/postgres/store.go | 1 + .../v2/datastore/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../imagecveedge/datastore/postgres/store.go | 1 + .../imageintegration/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../networkbaseline/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../datastore/store/postgres/store.go | 1 + .../datastore/store/postgres/store.go | 1 + .../nodecomponentedge/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + central/policy/store/postgres/store.go | 1 + .../policycategory/store/postgres/store.go | 1 + .../store/postgres/store.go | 1 + .../processbaseline/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../processindicator/store/postgres/store.go | 1 + .../store/postgres/store.go | 1 + .../k8srole/internal/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../reports/config/store/postgres/store.go | 1 + .../datastore/store/postgres/store.go | 1 + .../datastore/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../secret/internal/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + .../internal/store/postgres/store.go | 1 + pkg/search/postgres/common.go | 45 +++++++++++++++++++ pkg/search/postgres/store.go | 7 +++ pkg/search/postgres/store_cache.go | 5 +++ .../multitest/postgres/store.go | 1 + .../pg-table-bindings/store.go.tpl | 1 + .../pg-table-bindings/test/postgres/store.go | 1 + .../testgraphtables/testchild1/store.go | 1 + .../testgraphtables/testchild1p4/store.go | 1 + .../testgraphtables/testchild2/store.go | 1 + .../testg2grandchild1/store.go | 1 + .../testg3grandchild1/store.go | 1 + .../testgraphtables/testggrandchild1/store.go | 1 + .../testgraphtables/testgrandchild1/store.go | 1 + .../testgraphtables/testgrandparent/store.go | 1 + .../testgraphtables/testparent1/store.go | 1 + .../testgraphtables/testparent2/store.go | 1 + .../testgraphtables/testparent3/store.go | 1 + .../testgraphtables/testparent4/store.go | 1 + .../testgraphtables/testshortcircuit/store.go | 1 + .../testuuidkey/postgres/store.go | 1 + 84 files changed, 151 insertions(+) diff --git a/central/activecomponent/datastore/internal/store/postgres/store.go b/central/activecomponent/datastore/internal/store/postgres/store.go index 8ffcd045cd3d9..85f3759b85c82 100644 --- a/central/activecomponent/datastore/internal/store/postgres/store.go +++ b/central/activecomponent/datastore/internal/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/administration/events/datastore/internal/store/postgres/store.go b/central/administration/events/datastore/internal/store/postgres/store.go index a57fb69e93018..5441bd8049da0 100644 --- a/central/administration/events/datastore/internal/store/postgres/store.go +++ b/central/administration/events/datastore/internal/store/postgres/store.go @@ -50,6 +50,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/administration/usage/store/postgres/store.go b/central/administration/usage/store/postgres/store.go index d139c20332479..74aeef386d2b5 100644 --- a/central/administration/usage/store/postgres/store.go +++ b/central/administration/usage/store/postgres/store.go @@ -50,6 +50,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/alert/datastore/internal/store/mocks/store.go b/central/alert/datastore/internal/store/mocks/store.go index 5770c0b9c083b..8002df7370645 100644 --- a/central/alert/datastore/internal/store/mocks/store.go +++ b/central/alert/datastore/internal/store/mocks/store.go @@ -117,6 +117,20 @@ func (mr *MockStoreMockRecorder) GetByQuery(ctx, query any) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByQuery", reflect.TypeOf((*MockStore)(nil).GetByQuery), ctx, query) } +// GetByQueryFn mocks base method. +func (m *MockStore) GetByQueryFn(ctx context.Context, query *v1.Query, fn func(*storage.Alert) error) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetByQueryFn", ctx, query, fn) + ret0, _ := ret[0].(error) + return ret0 +} + +// GetByQueryFn indicates an expected call of GetByQueryFn. +func (mr *MockStoreMockRecorder) GetByQueryFn(ctx, query, fn any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetByQueryFn", reflect.TypeOf((*MockStore)(nil).GetByQueryFn), ctx, query, fn) +} + // GetIDs mocks base method. func (m *MockStore) GetIDs(ctx context.Context) ([]string, error) { m.ctrl.T.Helper() diff --git a/central/alert/datastore/internal/store/postgres/store.go b/central/alert/datastore/internal/store/postgres/store.go index 22be5c87fd669..bd171ca1633ae 100644 --- a/central/alert/datastore/internal/store/postgres/store.go +++ b/central/alert/datastore/internal/store/postgres/store.go @@ -53,6 +53,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/alert/datastore/internal/store/store.go b/central/alert/datastore/internal/store/store.go index 66ef8ba12cb60..3ceb55e4e6212 100644 --- a/central/alert/datastore/internal/store/store.go +++ b/central/alert/datastore/internal/store/store.go @@ -20,6 +20,7 @@ type Store interface { Get(ctx context.Context, id string) (*storage.Alert, bool, error) GetMany(ctx context.Context, ids []string) ([]*storage.Alert, []int, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storage.Alert, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storage.Alert) error) error Upsert(ctx context.Context, alert *storage.Alert) error UpsertMany(ctx context.Context, alerts []*storage.Alert) error Delete(ctx context.Context, id string) error diff --git a/central/apitoken/datastore/internal/store/postgres/store.go b/central/apitoken/datastore/internal/store/postgres/store.go index 00a1cac00e05a..5b43b756ba69b 100644 --- a/central/apitoken/datastore/internal/store/postgres/store.go +++ b/central/apitoken/datastore/internal/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/authprovider/datastore/internal/store/postgres/store.go b/central/authprovider/datastore/internal/store/postgres/store.go index 20d1c4220f1de..a418e435b04a3 100644 --- a/central/authprovider/datastore/internal/store/postgres/store.go +++ b/central/authprovider/datastore/internal/store/postgres/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) GetAll(ctx context.Context) ([]*storeType, error) diff --git a/central/blob/datastore/store/postgres/store.go b/central/blob/datastore/store/postgres/store.go index cb28c03124cc6..76590c7a96232 100644 --- a/central/blob/datastore/store/postgres/store.go +++ b/central/blob/datastore/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, name string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/cloudsources/datastore/internal/store/postgres/store.go b/central/cloudsources/datastore/internal/store/postgres/store.go index c90648db9a212..82d7c05c299c0 100644 --- a/central/cloudsources/datastore/internal/store/postgres/store.go +++ b/central/cloudsources/datastore/internal/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) GetAll(ctx context.Context) ([]*storeType, error) diff --git a/central/cluster/store/cluster/postgres/store.go b/central/cluster/store/cluster/postgres/store.go index 302b35baceb25..083bbf8a884c0 100644 --- a/central/cluster/store/cluster/postgres/store.go +++ b/central/cluster/store/cluster/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/cluster/store/clusterhealth/postgres/store.go b/central/cluster/store/clusterhealth/postgres/store.go index a919994bceed2..897e6195ade89 100644 --- a/central/cluster/store/clusterhealth/postgres/store.go +++ b/central/cluster/store/clusterhealth/postgres/store.go @@ -50,6 +50,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/clustercveedge/datastore/store/postgres/store.go b/central/clustercveedge/datastore/store/postgres/store.go index af6bea04754af..9d68d29c27889 100644 --- a/central/clustercveedge/datastore/store/postgres/store.go +++ b/central/clustercveedge/datastore/store/postgres/store.go @@ -40,6 +40,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/compliance/datastore/internal/store/postgres/domain/store.go b/central/compliance/datastore/internal/store/postgres/domain/store.go index 23ebacd011f04..3c484a4f1542f 100644 --- a/central/compliance/datastore/internal/store/postgres/domain/store.go +++ b/central/compliance/datastore/internal/store/postgres/domain/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/compliance/datastore/internal/store/postgres/metadata/store.go b/central/compliance/datastore/internal/store/postgres/metadata/store.go index e9256ab533e10..74da1cd87a9f8 100644 --- a/central/compliance/datastore/internal/store/postgres/metadata/store.go +++ b/central/compliance/datastore/internal/store/postgres/metadata/store.go @@ -53,6 +53,7 @@ type Store interface { Get(ctx context.Context, runID string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/compliance/datastore/internal/store/postgres/results/store.go b/central/compliance/datastore/internal/store/postgres/results/store.go index 6212bc4ca6f29..17be799cc0a8d 100644 --- a/central/compliance/datastore/internal/store/postgres/results/store.go +++ b/central/compliance/datastore/internal/store/postgres/results/store.go @@ -53,6 +53,7 @@ type Store interface { Get(ctx context.Context, runMetadataRunID string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/benchmarks/store/postgres/store.go b/central/complianceoperator/v2/benchmarks/store/postgres/store.go index 9911f550ca42a..2af7b97f98342 100644 --- a/central/complianceoperator/v2/benchmarks/store/postgres/store.go +++ b/central/complianceoperator/v2/benchmarks/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/checkresults/store/postgres/store.go b/central/complianceoperator/v2/checkresults/store/postgres/store.go index 0323e8ff0ee9f..b53f6b8fe41d2 100644 --- a/central/complianceoperator/v2/checkresults/store/postgres/store.go +++ b/central/complianceoperator/v2/checkresults/store/postgres/store.go @@ -53,6 +53,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/integration/store/postgres/store.go b/central/complianceoperator/v2/integration/store/postgres/store.go index 548078910be08..108cd1bf8b2c3 100644 --- a/central/complianceoperator/v2/integration/store/postgres/store.go +++ b/central/complianceoperator/v2/integration/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/profiles/store/postgres/store.go b/central/complianceoperator/v2/profiles/store/postgres/store.go index 69662cf139c95..29026dda0a248 100644 --- a/central/complianceoperator/v2/profiles/store/postgres/store.go +++ b/central/complianceoperator/v2/profiles/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/remediations/store/postgres/store.go b/central/complianceoperator/v2/remediations/store/postgres/store.go index d31e50cfec019..7e78a84eb0479 100644 --- a/central/complianceoperator/v2/remediations/store/postgres/store.go +++ b/central/complianceoperator/v2/remediations/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/report/store/postgres/store.go b/central/complianceoperator/v2/report/store/postgres/store.go index 4d1102eef04df..1309973adb34f 100644 --- a/central/complianceoperator/v2/report/store/postgres/store.go +++ b/central/complianceoperator/v2/report/store/postgres/store.go @@ -50,6 +50,7 @@ type Store interface { Get(ctx context.Context, reportID string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/rules/store/postgres/store.go b/central/complianceoperator/v2/rules/store/postgres/store.go index eebf3f6c0a075..6bcf5870967fb 100644 --- a/central/complianceoperator/v2/rules/store/postgres/store.go +++ b/central/complianceoperator/v2/rules/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/scanconfigurations/scanconfigstatus/store/postgres/store.go b/central/complianceoperator/v2/scanconfigurations/scanconfigstatus/store/postgres/store.go index e58c43e3e95bb..ed1d4effa0b61 100644 --- a/central/complianceoperator/v2/scanconfigurations/scanconfigstatus/store/postgres/store.go +++ b/central/complianceoperator/v2/scanconfigurations/scanconfigstatus/store/postgres/store.go @@ -53,6 +53,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/scanconfigurations/store/postgres/store.go b/central/complianceoperator/v2/scanconfigurations/store/postgres/store.go index 0720d03c96c44..035eeefed6e8f 100644 --- a/central/complianceoperator/v2/scanconfigurations/store/postgres/store.go +++ b/central/complianceoperator/v2/scanconfigurations/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/scans/store/postgres/store.go b/central/complianceoperator/v2/scans/store/postgres/store.go index e68bba811ab00..eecca2c365305 100644 --- a/central/complianceoperator/v2/scans/store/postgres/store.go +++ b/central/complianceoperator/v2/scans/store/postgres/store.go @@ -53,6 +53,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/scansettingbindings/store/postgres/store.go b/central/complianceoperator/v2/scansettingbindings/store/postgres/store.go index 5b3f52c74d503..3ac96a4543363 100644 --- a/central/complianceoperator/v2/scansettingbindings/store/postgres/store.go +++ b/central/complianceoperator/v2/scansettingbindings/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/complianceoperator/v2/suites/store/postgres/store.go b/central/complianceoperator/v2/suites/store/postgres/store.go index fa8a424a85737..dc9679bf2a711 100644 --- a/central/complianceoperator/v2/suites/store/postgres/store.go +++ b/central/complianceoperator/v2/suites/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/componentcveedge/datastore/store/postgres/store.go b/central/componentcveedge/datastore/store/postgres/store.go index 5a4555057756b..1622b25c0f928 100644 --- a/central/componentcveedge/datastore/store/postgres/store.go +++ b/central/componentcveedge/datastore/store/postgres/store.go @@ -40,6 +40,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/cve/cluster/datastore/store/postgres/store.go b/central/cve/cluster/datastore/store/postgres/store.go index 3faceb1b2d7ca..68b471f77da6e 100644 --- a/central/cve/cluster/datastore/store/postgres/store.go +++ b/central/cve/cluster/datastore/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/cve/image/datastore/store/postgres/store.go b/central/cve/image/datastore/store/postgres/store.go index 5c35cc45c7296..5cdee593cb4e1 100644 --- a/central/cve/image/datastore/store/postgres/store.go +++ b/central/cve/image/datastore/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/cve/image/v2/datastore/store/postgres/store.go b/central/cve/image/v2/datastore/store/postgres/store.go index c4d46c1cd3428..99b6fe762f692 100644 --- a/central/cve/image/v2/datastore/store/postgres/store.go +++ b/central/cve/image/v2/datastore/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/cve/node/datastore/store/postgres/store.go b/central/cve/node/datastore/store/postgres/store.go index 0b98d00ab37b4..7421655e3f7d7 100644 --- a/central/cve/node/datastore/store/postgres/store.go +++ b/central/cve/node/datastore/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/deployment/datastore/internal/store/postgres/store.go b/central/deployment/datastore/internal/store/postgres/store.go index 290780420bf22..6e16711001d1a 100644 --- a/central/deployment/datastore/internal/store/postgres/store.go +++ b/central/deployment/datastore/internal/store/postgres/store.go @@ -53,6 +53,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/discoveredclusters/datastore/internal/store/postgres/store.go b/central/discoveredclusters/datastore/internal/store/postgres/store.go index 84af947894bc8..27a00b857caa3 100644 --- a/central/discoveredclusters/datastore/internal/store/postgres/store.go +++ b/central/discoveredclusters/datastore/internal/store/postgres/store.go @@ -50,6 +50,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/imagecomponent/datastore/store/postgres/store.go b/central/imagecomponent/datastore/store/postgres/store.go index ac26c9cb029e8..f51fd11c542f2 100644 --- a/central/imagecomponent/datastore/store/postgres/store.go +++ b/central/imagecomponent/datastore/store/postgres/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/imagecomponent/v2/datastore/store/postgres/store.go b/central/imagecomponent/v2/datastore/store/postgres/store.go index 652299d7a5f49..2f50f2dd6a89c 100644 --- a/central/imagecomponent/v2/datastore/store/postgres/store.go +++ b/central/imagecomponent/v2/datastore/store/postgres/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/imagecomponentedge/datastore/internal/store/postgres/store.go b/central/imagecomponentedge/datastore/internal/store/postgres/store.go index c1752735417d6..00b65d1404a54 100644 --- a/central/imagecomponentedge/datastore/internal/store/postgres/store.go +++ b/central/imagecomponentedge/datastore/internal/store/postgres/store.go @@ -40,6 +40,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/imagecveedge/datastore/postgres/store.go b/central/imagecveedge/datastore/postgres/store.go index 40c9b7ada3162..c038c56797069 100644 --- a/central/imagecveedge/datastore/postgres/store.go +++ b/central/imagecveedge/datastore/postgres/store.go @@ -40,6 +40,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/imageintegration/store/postgres/store.go b/central/imageintegration/store/postgres/store.go index 0ac1aeb6bfe1d..a6e846314875a 100644 --- a/central/imageintegration/store/postgres/store.go +++ b/central/imageintegration/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) GetAll(ctx context.Context) ([]*storeType, error) diff --git a/central/namespace/datastore/internal/store/postgres/store.go b/central/namespace/datastore/internal/store/postgres/store.go index 76a7ab0c298bb..1704f363968e4 100644 --- a/central/namespace/datastore/internal/store/postgres/store.go +++ b/central/namespace/datastore/internal/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/networkbaseline/store/postgres/store.go b/central/networkbaseline/store/postgres/store.go index d58cb2f2249b1..32a44ff13e22a 100644 --- a/central/networkbaseline/store/postgres/store.go +++ b/central/networkbaseline/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, deploymentID string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/networkgraph/entity/datastore/internal/store/postgres/store.go b/central/networkgraph/entity/datastore/internal/store/postgres/store.go index bf8ca73c5036e..c32524c5f97f5 100644 --- a/central/networkgraph/entity/datastore/internal/store/postgres/store.go +++ b/central/networkgraph/entity/datastore/internal/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, infoID string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/networkpolicies/datastore/internal/store/postgres/store.go b/central/networkpolicies/datastore/internal/store/postgres/store.go index 17e56b39c4130..45305073b5659 100644 --- a/central/networkpolicies/datastore/internal/store/postgres/store.go +++ b/central/networkpolicies/datastore/internal/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/nodecomponent/datastore/store/postgres/store.go b/central/nodecomponent/datastore/store/postgres/store.go index 4dca9cb1cb050..3324c77df1a47 100644 --- a/central/nodecomponent/datastore/store/postgres/store.go +++ b/central/nodecomponent/datastore/store/postgres/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/nodecomponentcveedge/datastore/store/postgres/store.go b/central/nodecomponentcveedge/datastore/store/postgres/store.go index 07a22862b82c9..3616364c60272 100644 --- a/central/nodecomponentcveedge/datastore/store/postgres/store.go +++ b/central/nodecomponentcveedge/datastore/store/postgres/store.go @@ -40,6 +40,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/nodecomponentedge/store/postgres/store.go b/central/nodecomponentedge/store/postgres/store.go index ac7eb6f3793b9..dc7cadc86efd4 100644 --- a/central/nodecomponentedge/store/postgres/store.go +++ b/central/nodecomponentedge/store/postgres/store.go @@ -40,6 +40,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/pod/datastore/internal/store/postgres/store.go b/central/pod/datastore/internal/store/postgres/store.go index 8f77c4dd7ce15..8999ad770c401 100644 --- a/central/pod/datastore/internal/store/postgres/store.go +++ b/central/pod/datastore/internal/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/policy/store/postgres/store.go b/central/policy/store/postgres/store.go index 12dd29fdb24ec..a7a3ed3a2fae8 100644 --- a/central/policy/store/postgres/store.go +++ b/central/policy/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) GetAll(ctx context.Context) ([]*storeType, error) diff --git a/central/policycategory/store/postgres/store.go b/central/policycategory/store/postgres/store.go index 3e3731d1f6048..52c4c6925f230 100644 --- a/central/policycategory/store/postgres/store.go +++ b/central/policycategory/store/postgres/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) GetAll(ctx context.Context) ([]*storeType, error) diff --git a/central/policycategoryedge/store/postgres/store.go b/central/policycategoryedge/store/postgres/store.go index 41e51fd30e2fe..0a9c568d94a41 100644 --- a/central/policycategoryedge/store/postgres/store.go +++ b/central/policycategoryedge/store/postgres/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) GetAll(ctx context.Context) ([]*storeType, error) diff --git a/central/processbaseline/store/postgres/store.go b/central/processbaseline/store/postgres/store.go index 4fa61055d4783..bc6db18865f85 100644 --- a/central/processbaseline/store/postgres/store.go +++ b/central/processbaseline/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/processbaselineresults/datastore/internal/store/postgres/store.go b/central/processbaselineresults/datastore/internal/store/postgres/store.go index 8642b1845107e..9dc650158231a 100644 --- a/central/processbaselineresults/datastore/internal/store/postgres/store.go +++ b/central/processbaselineresults/datastore/internal/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, deploymentID string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/processindicator/store/postgres/store.go b/central/processindicator/store/postgres/store.go index 8cf959b091ea0..c2072851173c8 100644 --- a/central/processindicator/store/postgres/store.go +++ b/central/processindicator/store/postgres/store.go @@ -53,6 +53,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/processlisteningonport/store/postgres/store.go b/central/processlisteningonport/store/postgres/store.go index f151f36c59f90..ece25ba15cdd8 100644 --- a/central/processlisteningonport/store/postgres/store.go +++ b/central/processlisteningonport/store/postgres/store.go @@ -53,6 +53,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/rbac/k8srole/internal/store/postgres/store.go b/central/rbac/k8srole/internal/store/postgres/store.go index 083d49ba01246..d2754235dd3e8 100644 --- a/central/rbac/k8srole/internal/store/postgres/store.go +++ b/central/rbac/k8srole/internal/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/rbac/k8srolebinding/internal/store/postgres/store.go b/central/rbac/k8srolebinding/internal/store/postgres/store.go index a1907e1571c36..647896dec9429 100644 --- a/central/rbac/k8srolebinding/internal/store/postgres/store.go +++ b/central/rbac/k8srolebinding/internal/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/reports/config/store/postgres/store.go b/central/reports/config/store/postgres/store.go index c9a43d0b0511d..45751dd21d368 100644 --- a/central/reports/config/store/postgres/store.go +++ b/central/reports/config/store/postgres/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/reports/snapshot/datastore/store/postgres/store.go b/central/reports/snapshot/datastore/store/postgres/store.go index 46d719b5d9f67..4578732c55718 100644 --- a/central/reports/snapshot/datastore/store/postgres/store.go +++ b/central/reports/snapshot/datastore/store/postgres/store.go @@ -50,6 +50,7 @@ type Store interface { Get(ctx context.Context, reportID string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/resourcecollection/datastore/store/postgres/store.go b/central/resourcecollection/datastore/store/postgres/store.go index f1a38a3c3a6e9..c778b45eb3a89 100644 --- a/central/resourcecollection/datastore/store/postgres/store.go +++ b/central/resourcecollection/datastore/store/postgres/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/risk/datastore/internal/store/postgres/store.go b/central/risk/datastore/internal/store/postgres/store.go index 62a02e1573d31..0f9bb91a87e28 100644 --- a/central/risk/datastore/internal/store/postgres/store.go +++ b/central/risk/datastore/internal/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/secret/internal/store/postgres/store.go b/central/secret/internal/store/postgres/store.go index 3b40a572f8751..caaa21745d131 100644 --- a/central/secret/internal/store/postgres/store.go +++ b/central/secret/internal/store/postgres/store.go @@ -53,6 +53,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/serviceaccount/internal/store/postgres/store.go b/central/serviceaccount/internal/store/postgres/store.go index 7469e9686b542..5236d2f8e99d6 100644 --- a/central/serviceaccount/internal/store/postgres/store.go +++ b/central/serviceaccount/internal/store/postgres/store.go @@ -52,6 +52,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/central/vulnmgmt/vulnerabilityrequest/datastore/internal/store/postgres/store.go b/central/vulnmgmt/vulnerabilityrequest/datastore/internal/store/postgres/store.go index 7393e30f612fe..73b1eb5b36469 100644 --- a/central/vulnmgmt/vulnerabilityrequest/datastore/internal/store/postgres/store.go +++ b/central/vulnmgmt/vulnerabilityrequest/datastore/internal/store/postgres/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/pkg/search/postgres/common.go b/pkg/search/postgres/common.go index 240ea84bbde5d..344f6f8499202 100644 --- a/pkg/search/postgres/common.go +++ b/pkg/search/postgres/common.go @@ -943,6 +943,8 @@ func RunCountRequestForSchema(ctx context.Context, schema *walker.Schema, q *v1. } // RunGetQueryForSchema executes a request for just the search against the database +// +// Deprecated: use RunGetQueryForSchemaFn instead func RunGetQueryForSchema[T any, PT pgutils.Unmarshaler[T]](ctx context.Context, schema *walker.Schema, q *v1.Query, db postgres.DB) (*T, error) { if q == nil { q = searchPkg.EmptyQuery() @@ -964,6 +966,49 @@ func RunGetQueryForSchema[T any, PT pgutils.Unmarshaler[T]](ctx context.Context, }) } +func retryableGetRows(ctx context.Context, schema *walker.Schema, q *v1.Query, db postgres.DB) (*tracedRows, error) { + if q == nil { + q = searchPkg.EmptyQuery() + } + + query, err := standardizeQueryAndPopulatePath(ctx, q, schema, GET) + if err != nil { + return nil, errors.Wrap(err, "error creating query") + } + if query == nil { + return nil, emptyQueryErr + } + + queryStr := query.AsSQL() + return tracedQuery(ctx, db, queryStr, query.Data...) +} + +// RunGetQueryForSchemaFn runs a query and call a callback for each row. It stops on first error. +func RunGetQueryForSchemaFn[T any, PT pgutils.Unmarshaler[T]](ctx context.Context, schema *walker.Schema, q *v1.Query, db postgres.DB, callback func(obj PT) error) error { + rows, err := pgutils.Retry2(ctx, func() (*tracedRows, error) { + return retryableGetRows(ctx, schema, q, db) + }) + if err != nil { + return err + } + defer rows.Close() + + var data []byte + _, err = pgx.ForEachRow(rows, []any{&data}, func() error { + msg := new(T) + if errUnmarshal := PT(msg).UnmarshalVTUnsafe(data); errUnmarshal != nil { + return errUnmarshal + } + return callback(msg) + }) + + if err != nil { + return errors.Wrap(err, "processing rows") + } + + return nil +} + func retryableRunGetManyQueryForSchema[T any, PT pgutils.Unmarshaler[T]](ctx context.Context, query *query, db postgres.DB) ([]*T, error) { queryStr := query.AsSQL() rows, err := tracedQuery(ctx, db, queryStr, query.Data...) diff --git a/pkg/search/postgres/store.go b/pkg/search/postgres/store.go index 8b7aff8455f08..6285038da5e43 100644 --- a/pkg/search/postgres/store.go +++ b/pkg/search/postgres/store.go @@ -66,6 +66,7 @@ type Store[T any, PT pgutils.Unmarshaler[T]] interface { GetAll(ctx context.Context) ([]PT, error) Get(ctx context.Context, id string) (PT, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*T, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj PT) error) error GetIDs(ctx context.Context) ([]string, error) GetIDsByQuery(ctx context.Context, query *v1.Query) ([]string, error) GetMany(ctx context.Context, identifiers []string) ([]PT, []int, error) @@ -247,6 +248,12 @@ func (s *genericStore[T, PT]) GetByQuery(ctx context.Context, query *v1.Query) ( return rows, nil } +// GetByQueryFn returns the objects from the store matching the query. +func (s *genericStore[T, PT]) GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj PT) error) error { + defer s.setPostgresOperationDurationTime(time.Now(), ops.GetByQuery) + return RunGetQueryForSchemaFn[T, PT](ctx, s.schema, query, s.db, fn) +} + func (s *genericStore[T, PT]) fetchIDsByQuery(ctx context.Context, query *v1.Query) ([]string, error) { result, err := RunSearchRequestForSchema(ctx, s.schema, query, s.db) if err != nil { diff --git a/pkg/search/postgres/store_cache.go b/pkg/search/postgres/store_cache.go index a8e975eedd285..8e9a91897e23f 100644 --- a/pkg/search/postgres/store_cache.go +++ b/pkg/search/postgres/store_cache.go @@ -372,6 +372,11 @@ func (c *cachedStore[T, PT]) GetByQuery(ctx context.Context, query *v1.Query) ([ return results, nil } +// GetByQueryFn calls the objects from the store matching the query. +func (c *cachedStore[T, PT]) GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj PT) error) error { + return c.underlyingStore.GetByQueryFn(ctx, query, fn) +} + // DeleteByQuery removes the objects from the store based on the passed query. func (c *cachedStore[T, PT]) DeleteByQuery(ctx context.Context, query *v1.Query) ([]string, error) { identifiersToRemove, err := c.underlyingStore.DeleteByQuery(ctx, query) diff --git a/tools/generate-helpers/pg-table-bindings/multitest/postgres/store.go b/tools/generate-helpers/pg-table-bindings/multitest/postgres/store.go index 87439b5dcdc1f..b854ee6b0e866 100644 --- a/tools/generate-helpers/pg-table-bindings/multitest/postgres/store.go +++ b/tools/generate-helpers/pg-table-bindings/multitest/postgres/store.go @@ -50,6 +50,7 @@ type Store interface { Get(ctx context.Context, key1 string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/store.go.tpl b/tools/generate-helpers/pg-table-bindings/store.go.tpl index a655ee38c1173..1cf58d2525039 100644 --- a/tools/generate-helpers/pg-table-bindings/store.go.tpl +++ b/tools/generate-helpers/pg-table-bindings/store.go.tpl @@ -84,6 +84,7 @@ type Store interface { Get(ctx context.Context, {{template "paramList" $pks}}) (*storeType, bool, error) {{- if .SearchCategory }} GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error {{- end }} GetMany(ctx context.Context, identifiers []{{$singlePK.Type}}) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]{{$singlePK.Type}}, error) diff --git a/tools/generate-helpers/pg-table-bindings/test/postgres/store.go b/tools/generate-helpers/pg-table-bindings/test/postgres/store.go index 7f792af443114..7aa6f129870ac 100644 --- a/tools/generate-helpers/pg-table-bindings/test/postgres/store.go +++ b/tools/generate-helpers/pg-table-bindings/test/postgres/store.go @@ -50,6 +50,7 @@ type Store interface { Get(ctx context.Context, key string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) GetAll(ctx context.Context) ([]*storeType, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild1/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild1/store.go index aacab35d5ff4a..41c268eec4116 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild1/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild1/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild1p4/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild1p4/store.go index 5a8ee24f2487a..70c26c219563d 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild1p4/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild1p4/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild2/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild2/store.go index 44292a1ae416a..cf4440d87f9f1 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild2/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testchild2/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testg2grandchild1/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testg2grandchild1/store.go index 0af7ada2a98a6..2cde65c5949b5 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testg2grandchild1/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testg2grandchild1/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testg3grandchild1/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testg3grandchild1/store.go index e4001f3ee2cd4..ff50da2901c3e 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testg3grandchild1/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testg3grandchild1/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testggrandchild1/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testggrandchild1/store.go index 4b498cb0e7eb6..a5ad8bb5fe54c 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testggrandchild1/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testggrandchild1/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testgrandchild1/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testgrandchild1/store.go index ec4b9bff660d3..c52c81234afd4 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testgrandchild1/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testgrandchild1/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testgrandparent/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testgrandparent/store.go index f0f936c08cc7b..918ab95d9fa9f 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testgrandparent/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testgrandparent/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent1/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent1/store.go index 533c2e3456e03..2feb18ae2f1c7 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent1/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent1/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent2/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent2/store.go index ca06a7978f81c..cbebc1f674a7e 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent2/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent2/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent3/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent3/store.go index 0c0065d6abd62..e0ebac63c432a 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent3/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent3/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent4/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent4/store.go index b7de6ae33357f..d9c7d23e5be59 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent4/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testparent4/store.go @@ -49,6 +49,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testgraphtables/testshortcircuit/store.go b/tools/generate-helpers/pg-table-bindings/testgraphtables/testshortcircuit/store.go index 479882d2d0b79..25957db4c4783 100644 --- a/tools/generate-helpers/pg-table-bindings/testgraphtables/testshortcircuit/store.go +++ b/tools/generate-helpers/pg-table-bindings/testgraphtables/testshortcircuit/store.go @@ -48,6 +48,7 @@ type Store interface { Get(ctx context.Context, id string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) diff --git a/tools/generate-helpers/pg-table-bindings/testuuidkey/postgres/store.go b/tools/generate-helpers/pg-table-bindings/testuuidkey/postgres/store.go index 396c6913b5060..9fd367a8392a2 100644 --- a/tools/generate-helpers/pg-table-bindings/testuuidkey/postgres/store.go +++ b/tools/generate-helpers/pg-table-bindings/testuuidkey/postgres/store.go @@ -50,6 +50,7 @@ type Store interface { Get(ctx context.Context, key string) (*storeType, bool, error) GetByQuery(ctx context.Context, query *v1.Query) ([]*storeType, error) + GetByQueryFn(ctx context.Context, query *v1.Query, fn func(obj *storeType) error) error GetMany(ctx context.Context, identifiers []string) ([]*storeType, []int, error) GetIDs(ctx context.Context) ([]string, error) GetAll(ctx context.Context) ([]*storeType, error) From 83a63ac7166a5dbd43ff8822d3806460138bbe17 Mon Sep 17 00:00:00 2001 From: Mladen Todorovic Date: Mon, 17 Mar 2025 11:26:53 +0100 Subject: [PATCH 2/2] Use GetByQueryFn in SearchListAlerts --- .../alert/datastore/internal/search/searcher_impl.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/central/alert/datastore/internal/search/searcher_impl.go b/central/alert/datastore/internal/search/searcher_impl.go index e5b17259d6e31..ede68dcce1c94 100644 --- a/central/alert/datastore/internal/search/searcher_impl.go +++ b/central/alert/datastore/internal/search/searcher_impl.go @@ -41,16 +41,15 @@ func (ds *searcherImpl) SearchListAlerts(ctx context.Context, q *v1.Query, exclu if excludeResolved { q = applyDefaultState(q) } - alerts, err := ds.storage.GetByQuery(ctx, q) + listAlerts := make([]*storage.ListAlert, 0, q.GetPagination().GetLimit()) + err := ds.storage.GetByQueryFn(ctx, q, func(alert *storage.Alert) error { + listAlerts = append(listAlerts, convert.AlertToListAlert(alert)) + return nil + }) if err != nil { return nil, err } - listAlerts := make([]*storage.ListAlert, 0, len(alerts)) - for _, alert := range alerts { - listAlerts = append(listAlerts, convert.AlertToListAlert(alert)) - } return listAlerts, nil - } // SearchRawAlerts retrieves Alerts from the storage