summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-09-04 20:22:16 +0000
committerRobert Speicher <robert@gitlab.com>2018-09-04 20:22:16 +0000
commit91003c6ebb764c9cf3fe01a14d6213b26c09dcc8 (patch)
tree43bb8d7edbc6ffe4a713c7b87856dbd2ed268c8f
parent265b49135436af9b8938c4b21b13462f0cfffdcb (diff)
parentd4bdcfbf19b594646d597bae5eb6d0c0f7354362 (diff)
downloadgitlab-ce-91003c6ebb764c9cf3fe01a14d6213b26c09dcc8.tar.gz
Merge branch 'sh-disable-unnecessary-avatar-revalidation' into 'master'
Disable project avatar validation if avatar has not changed Closes #51053 See merge request gitlab-org/gitlab-ce!21506
-rw-r--r--app/models/concerns/avatarable.rb2
-rw-r--r--changelogs/unreleased/sh-disable-unnecessary-avatar-revalidation.yml5
-rw-r--r--spec/models/concerns/avatarable_spec.rb20
3 files changed, 26 insertions, 1 deletions
diff --git a/app/models/concerns/avatarable.rb b/app/models/concerns/avatarable.rb
index c0233661a9b..0d5311a9985 100644
--- a/app/models/concerns/avatarable.rb
+++ b/app/models/concerns/avatarable.rb
@@ -9,7 +9,7 @@ module Avatarable
include Gitlab::Utils::StrongMemoize
validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? }
- validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
+ validates :avatar, file_size: { maximum: 200.kilobytes.to_i }, if: :avatar_changed?
mount_uploader :avatar, AvatarUploader
diff --git a/changelogs/unreleased/sh-disable-unnecessary-avatar-revalidation.yml b/changelogs/unreleased/sh-disable-unnecessary-avatar-revalidation.yml
new file mode 100644
index 00000000000..386410484fe
--- /dev/null
+++ b/changelogs/unreleased/sh-disable-unnecessary-avatar-revalidation.yml
@@ -0,0 +1,5 @@
+---
+title: Disable project avatar validation if avatar has not changed
+merge_request:
+author:
+type: performance
diff --git a/spec/models/concerns/avatarable_spec.rb b/spec/models/concerns/avatarable_spec.rb
index 76f734079b7..7d617cb7b19 100644
--- a/spec/models/concerns/avatarable_spec.rb
+++ b/spec/models/concerns/avatarable_spec.rb
@@ -12,6 +12,26 @@ describe Avatarable do
stub_config_setting(relative_url_root: relative_url_root)
end
+ describe '#update' do
+ let(:validator) { project._validators[:avatar].detect { |v| v.is_a?(FileSizeValidator) } }
+
+ context 'when avatar changed' do
+ it 'validates the file size' do
+ expect(validator).to receive(:validate_each).and_call_original
+
+ project.update(avatar: 'uploads/avatar.png')
+ end
+ end
+
+ context 'when avatar was not changed' do
+ it 'skips validation of file size' do
+ expect(validator).not_to receive(:validate_each)
+
+ project.update(name: 'Hello world')
+ end
+ end
+ end
+
describe '#avatar_path' do
using RSpec::Parameterized::TableSyntax