mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-17 20:19:55 +00:00
change getGroupsByPeers
This commit is contained in:
@@ -1448,25 +1448,15 @@ func (s *SqlStore) GetPeerGroups(ctx context.Context, lockStrength LockingStreng
|
||||
tx = tx.Clauses(clause.Locking{Strength: string(lockStrength)})
|
||||
}
|
||||
|
||||
var groupIDs []string
|
||||
err := tx.
|
||||
Table("group_peers").
|
||||
Where("peer_id = ?", peerId).
|
||||
Pluck("group_id", &groupIDs).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(groupIDs) == 0 {
|
||||
return []*types.Group{}, nil // no matches
|
||||
}
|
||||
|
||||
var groups []*types.Group
|
||||
err = tx.
|
||||
Where("id IN ?", groupIDs).
|
||||
Preload("GroupPeers").
|
||||
Find(&groups).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
query := tx.
|
||||
Joins("JOIN group_peers ON group_peers.group_id = groups.id").
|
||||
Where("group_peers.peer_id = ?", peerId).
|
||||
Preload(clause.Associations).
|
||||
Find(&groups)
|
||||
|
||||
if query.Error != nil {
|
||||
return nil, query.Error
|
||||
}
|
||||
|
||||
for _, group := range groups {
|
||||
|
||||
@@ -1367,12 +1367,14 @@ func TestSqlStore_SaveGroups(t *testing.T) {
|
||||
AccountID: accountID,
|
||||
Issued: "api",
|
||||
Peers: []string{"peer1", "peer2"},
|
||||
Resources: []types.Resource{},
|
||||
},
|
||||
{
|
||||
ID: "group-2",
|
||||
AccountID: accountID,
|
||||
Issued: "integration",
|
||||
Peers: []string{"peer3", "peer4"},
|
||||
Resources: []types.Resource{},
|
||||
},
|
||||
}
|
||||
err = store.SaveGroups(context.Background(), LockingStrengthUpdate, accountID, groups)
|
||||
|
||||
Reference in New Issue
Block a user