From 74b525d77ba1503383fb45f5b77a61bce2d6a26a Mon Sep 17 00:00:00 2001 From: jasonkarel Date: Fri, 21 Feb 2025 13:03:22 +0700 Subject: [PATCH] fix memory iterations --- .../accountinfrastructure/accountmemory/workspace.go | 10 ++++++++-- .../accountinfrastructure/accountmongo/workspace.go | 12 +++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/account/accountinfrastructure/accountmemory/workspace.go b/account/accountinfrastructure/accountmemory/workspace.go index a9ea484..cee44de 100644 --- a/account/accountinfrastructure/accountmemory/workspace.go +++ b/account/accountinfrastructure/accountmemory/workspace.go @@ -6,7 +6,6 @@ import ( "github.com/reearth/reearthx/account/accountdomain" "github.com/reearth/reearthx/account/accountdomain/workspace" "github.com/reearth/reearthx/account/accountusecase/accountrepo" - "github.com/reearth/reearthx/idx" "github.com/reearth/reearthx/rerror" "github.com/reearth/reearthx/util" "golang.org/x/exp/slices" @@ -66,9 +65,16 @@ func (r *Workspace) FindByIntegrations(_ context.Context, ids workspace.Integrat } res := r.data.FindAll(func(key workspace.ID, value *workspace.Workspace) bool { - return value.Members().HasIntegration(idx.ID[accountdomain.Integration](key)) + for _, id := range ids { + if value.Members().HasIntegration(id) { + return true + } + } + return false }) + slices.SortFunc(res, func(a, b *workspace.Workspace) int { return a.ID().Compare(b.ID()) }) + return res, nil } diff --git a/account/accountinfrastructure/accountmongo/workspace.go b/account/accountinfrastructure/accountmongo/workspace.go index 2eceb82..348fad5 100644 --- a/account/accountinfrastructure/accountmongo/workspace.go +++ b/account/accountinfrastructure/accountmongo/workspace.go @@ -59,13 +59,13 @@ func (r *Workspace) FindByIntegration(ctx context.Context, id workspace.Integrat } // FindByIntegrations finds workspace list based on integrations IDs -func (r *Workspace) FindByIntegrations(ctx context.Context, ids workspace.IntegrationIDList) (workspace.List, error) { - if len(ids) == 0 { +func (r *Workspace) FindByIntegrations(ctx context.Context, integrationIDs workspace.IntegrationIDList) (workspace.List, error) { + if len(integrationIDs) == 0 { return nil, nil } - orConditions := make([]bson.M, len(ids)) - for i, id := range ids { + orConditions := make([]bson.M, len(integrationIDs)) + for i, id := range integrationIDs { orConditions[i] = bson.M{ "integrations." + strings.Replace(id.String(), ".", "", -1): bson.M{ "$exists": true, @@ -73,7 +73,9 @@ func (r *Workspace) FindByIntegrations(ctx context.Context, ids workspace.Integr } } - return r.find(ctx, bson.M{"$or": orConditions}) + return r.find(ctx, bson.M{ + "$or": orConditions, + }) } func (r *Workspace) FindByIDs(ctx context.Context, ids accountdomain.WorkspaceIDList) (workspace.List, error) {