fix peer add if group not existing

This commit is contained in:
Pascal Fischer
2025-07-03 15:30:35 +02:00
parent d25da87957
commit dfad334780

View File

@@ -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
})
}