mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-19 16:56:39 +00:00
fix peer add if group not existing
This commit is contained in:
@@ -460,17 +460,6 @@ func (s *SqlStore) SaveGroups(ctx context.Context, lockStrength LockingStrength,
|
||||
}
|
||||
|
||||
return s.db.Transaction(func(tx *gorm.DB) error {
|
||||
for _, g := range groups {
|
||||
g.StoreGroupPeers()
|
||||
|
||||
if err := tx.Model(&g).
|
||||
Association("GroupPeers").
|
||||
Replace(g.GroupPeers); err != nil {
|
||||
log.WithContext(ctx).Errorf("failed to save group peers to store: %s", err)
|
||||
return status.Errorf(status.Internal, "failed to save group peers to store")
|
||||
}
|
||||
}
|
||||
|
||||
result := tx.Session(&gorm.Session{FullSaveAssociations: true}).
|
||||
Clauses(
|
||||
clause.Locking{Strength: string(lockStrength)},
|
||||
@@ -485,6 +474,17 @@ func (s *SqlStore) SaveGroups(ctx context.Context, lockStrength LockingStrength,
|
||||
return status.Errorf(status.Internal, "failed to save groups to store")
|
||||
}
|
||||
|
||||
for _, g := range groups {
|
||||
g.StoreGroupPeers()
|
||||
|
||||
if err := tx.Model(&g).
|
||||
Association("GroupPeers").
|
||||
Replace(g.GroupPeers); err != nil {
|
||||
log.WithContext(ctx).Errorf("failed to save group peers to store: %s", err)
|
||||
return status.Errorf(status.Internal, "failed to save group peers to store")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user