From 445cdfa0241c73765fe3d1e571d9139e944561cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sat, 27 May 2023 20:09:02 +0200 Subject: [PATCH] Only validate display name when updated Otherwise we needlessly fetch the validated one from LDAP every time a model is saved. --- app/models/user.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 07d1bbe..855fd0d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -33,7 +33,8 @@ class User < ApplicationRecord validates_uniqueness_of :email validates :email, email: true - validates_length_of :display_name, minimum: 3, maximum: 35, allow_blank: true + validates_length_of :display_name, minimum: 3, maximum: 35, allow_blank: true, + if: -> { defined?(@display_name) } scope :confirmed, -> { where.not(confirmed_at: nil) } scope :pending, -> { where(confirmed_at: nil) }