mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-09 14:53:00 +03:00
fix: run user group count inside a transaction
This commit is contained in:
@@ -1175,13 +1175,19 @@ func (s *OidcService) GetDeviceCodeInfo(ctx context.Context, userCode string, us
|
||||
}
|
||||
|
||||
func (s *OidcService) GetAllowedGroupsCountOfClient(ctx context.Context, id string) (int64, error) {
|
||||
// We only perform select queries here, so we can rollback in all cases
|
||||
tx := s.db.Begin()
|
||||
defer func() {
|
||||
tx.Rollback()
|
||||
}()
|
||||
|
||||
var client model.OidcClient
|
||||
err := s.db.WithContext(ctx).Where("id = ?", id).First(&client).Error
|
||||
err := tx.WithContext(ctx).Where("id = ?", id).First(&client).Error
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
count := s.db.WithContext(ctx).Model(&client).Association("AllowedUserGroups").Count()
|
||||
count := tx.WithContext(ctx).Model(&client).Association("AllowedUserGroups").Count()
|
||||
return count, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user