mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-29 07:49:14 +01: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)})
|
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
|
var groups []*types.Group
|
||||||
err = tx.
|
query := tx.
|
||||||
Where("id IN ?", groupIDs).
|
Joins("JOIN group_peers ON group_peers.group_id = groups.id").
|
||||||
Preload("GroupPeers").
|
Where("group_peers.peer_id = ?", peerId).
|
||||||
Find(&groups).Error
|
Preload(clause.Associations).
|
||||||
if err != nil {
|
Find(&groups)
|
||||||
return nil, err
|
|
||||||
|
if query.Error != nil {
|
||||||
|
return nil, query.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
|
|||||||
@@ -1367,12 +1367,14 @@ func TestSqlStore_SaveGroups(t *testing.T) {
|
|||||||
AccountID: accountID,
|
AccountID: accountID,
|
||||||
Issued: "api",
|
Issued: "api",
|
||||||
Peers: []string{"peer1", "peer2"},
|
Peers: []string{"peer1", "peer2"},
|
||||||
|
Resources: []types.Resource{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ID: "group-2",
|
ID: "group-2",
|
||||||
AccountID: accountID,
|
AccountID: accountID,
|
||||||
Issued: "integration",
|
Issued: "integration",
|
||||||
Peers: []string{"peer3", "peer4"},
|
Peers: []string{"peer3", "peer4"},
|
||||||
|
Resources: []types.Resource{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
err = store.SaveGroups(context.Background(), LockingStrengthUpdate, accountID, groups)
|
err = store.SaveGroups(context.Background(), LockingStrengthUpdate, accountID, groups)
|
||||||
|
|||||||
Reference in New Issue
Block a user