mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-28 13:16: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 {
|
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}).
|
result := tx.Session(&gorm.Session{FullSaveAssociations: true}).
|
||||||
Clauses(
|
Clauses(
|
||||||
clause.Locking{Strength: string(lockStrength)},
|
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")
|
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
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user