This commit is contained in:
Pascal Fischer
2025-07-03 18:10:00 +02:00
parent dfb47d5545
commit f2990e2fbc
4 changed files with 57 additions and 45 deletions

View File

@@ -208,7 +208,7 @@ func (s *SqlStore) SaveAccount(ctx context.Context, account *types.Account) erro
result = tx.
Session(&gorm.Session{FullSaveAssociations: true}).
// Clauses(clause.OnConflict{UpdateAll: true}).
Clauses(clause.OnConflict{UpdateAll: true}).
Create(account)
if result.Error != nil {
return result.Error
@@ -459,6 +459,10 @@ func (s *SqlStore) SaveGroups(ctx context.Context, lockStrength LockingStrength,
return nil
}
for _, g := range groups {
g.StoreGroupPeers()
}
return s.db.Transaction(func(tx *gorm.DB) error {
result := tx.
Clauses(
@@ -1773,6 +1777,15 @@ func (s *SqlStore) GetGroupByName(ctx context.Context, lockStrength LockingStren
// we may need to reconsider changing the types.
query := tx.Preload(clause.Associations)
switch s.storeEngine {
case types.PostgresStoreEngine:
query = query.Order("json_array_length(peers::json) DESC")
case types.MysqlStoreEngine:
query = query.Order("JSON_LENGTH(JSON_EXTRACT(peers, \"$\")) DESC")
default:
query = query.Order("json_array_length(peers) DESC")
}
result := query.First(&group, "account_id = ? AND name = ?", accountID, groupName)
if err := result.Error; err != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {