From 8c352ff60e6e95e011634e5250df86c29227a351 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Sat, 29 Jun 2024 18:14:47 +0500 Subject: [PATCH] feat(bolt): optimize query --- db/bolt/integrations.go | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/db/bolt/integrations.go b/db/bolt/integrations.go index af8873d5..0903f9a1 100644 --- a/db/bolt/integrations.go +++ b/db/bolt/integrations.go @@ -69,19 +69,11 @@ func (d *BoltDb) CreateIntegrationExtractValue(projectId int, value db.Integrati func (d *BoltDb) GetIntegrationExtractValues(projectID int, params db.RetrieveQueryParams, integrationID int) (values []db.IntegrationExtractValue, err error) { values = make([]db.IntegrationExtractValue, 0) - var allValues []db.IntegrationExtractValue - err = d.getObjects(projectID, db.IntegrationExtractValueProps, params, nil, &allValues) - - if err != nil { - return - } - - for _, v := range allValues { - if v.IntegrationID == integrationID { - values = append(values, v) - } - } + err = d.getObjects(projectID, db.IntegrationExtractValueProps, params, func(i interface{}) bool { + v := i.(db.IntegrationExtractValue) + return v.IntegrationID == integrationID + }, &values) return } @@ -120,19 +112,11 @@ func (d *BoltDb) CreateIntegrationMatcher(projectID int, matcher db.IntegrationM func (d *BoltDb) GetIntegrationMatchers(projectID int, params db.RetrieveQueryParams, integrationID int) (matchers []db.IntegrationMatcher, err error) { matchers = make([]db.IntegrationMatcher, 0) - var allMatchers []db.IntegrationMatcher - err = d.getObjects(projectID, db.IntegrationMatcherProps, db.RetrieveQueryParams{}, nil, &allMatchers) - - if err != nil { - return - } - - for _, v := range allMatchers { - if v.IntegrationID == integrationID { - matchers = append(matchers, v) - } - } + err = d.getObjects(projectID, db.IntegrationMatcherProps, db.RetrieveQueryParams{}, func(i interface{}) bool { + v := i.(db.IntegrationExtractValue) + return v.IntegrationID == integrationID + }, &matchers) return }