Skip to content

Commit

Permalink
fix memory iterations
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkarel committed Feb 21, 2025
1 parent b555e67 commit 74b525d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 8 additions & 2 deletions account/accountinfrastructure/accountmemory/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -66,9 +65,16 @@ func (r *Workspace) FindByIntegrations(_ context.Context, ids workspace.Integrat
}

Check warning on line 65 in account/accountinfrastructure/accountmemory/workspace.go

View check run for this annotation

Codecov / codecov/patch

account/accountinfrastructure/accountmemory/workspace.go#L63-L65

Added lines #L63 - L65 were not covered by tests

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
}

Check warning on line 71 in account/accountinfrastructure/accountmemory/workspace.go

View check run for this annotation

Codecov / codecov/patch

account/accountinfrastructure/accountmemory/workspace.go#L67-L71

Added lines #L67 - L71 were not covered by tests
}
return false

Check warning on line 73 in account/accountinfrastructure/accountmemory/workspace.go

View check run for this annotation

Codecov / codecov/patch

account/accountinfrastructure/accountmemory/workspace.go#L73

Added line #L73 was not covered by tests
})

slices.SortFunc(res, func(a, b *workspace.Workspace) int { return a.ID().Compare(b.ID()) })

Check warning on line 76 in account/accountinfrastructure/accountmemory/workspace.go

View check run for this annotation

Codecov / codecov/patch

account/accountinfrastructure/accountmemory/workspace.go#L76

Added line #L76 was not covered by tests

return res, nil

Check warning on line 78 in account/accountinfrastructure/accountmemory/workspace.go

View check run for this annotation

Codecov / codecov/patch

account/accountinfrastructure/accountmemory/workspace.go#L78

Added line #L78 was not covered by tests
}

Expand Down
12 changes: 7 additions & 5 deletions account/accountinfrastructure/accountmongo/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,23 @@ 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
}

Check warning on line 65 in account/accountinfrastructure/accountmongo/workspace.go

View check run for this annotation

Codecov / codecov/patch

account/accountinfrastructure/accountmongo/workspace.go#L62-L65

Added lines #L62 - L65 were not covered by tests

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,
},
}
}

Check warning on line 74 in account/accountinfrastructure/accountmongo/workspace.go

View check run for this annotation

Codecov / codecov/patch

account/accountinfrastructure/accountmongo/workspace.go#L67-L74

Added lines #L67 - L74 were not covered by tests

return r.find(ctx, bson.M{"$or": orConditions})
return r.find(ctx, bson.M{
"$or": orConditions,
})

Check warning on line 78 in account/accountinfrastructure/accountmongo/workspace.go

View check run for this annotation

Codecov / codecov/patch

account/accountinfrastructure/accountmongo/workspace.go#L76-L78

Added lines #L76 - L78 were not covered by tests
}

func (r *Workspace) FindByIDs(ctx context.Context, ids accountdomain.WorkspaceIDList) (workspace.List, error) {
Expand Down

0 comments on commit 74b525d

Please sign in to comment.