From 09566ccc2c925cde352f8fba7c2db5e717e31063 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Tue, 4 Apr 2023 09:32:48 +0300 Subject: [PATCH] Version 3.3.4 (#128) * Don't trigger callback if file didn't change * Add changelog --- CHANGELOG.md | 6 ++++++ lib/uploadcare/rails/active_record/mount_uploadcare_file.rb | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fce8e093..d0c73542 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based now on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 3.3.4 — 2023-04-04 + +### Changed + +* Skipped network requests when the file attribute was unchanged (fixed https://github.com/uploadcare/uploadcare-rails/issues/127) + ## 3.3.3 — 2023-03-27 ### Changed diff --git a/lib/uploadcare/rails/active_record/mount_uploadcare_file.rb b/lib/uploadcare/rails/active_record/mount_uploadcare_file.rb index 964aa5cd..069b8aa4 100644 --- a/lib/uploadcare/rails/active_record/mount_uploadcare_file.rb +++ b/lib/uploadcare/rails/active_record/mount_uploadcare_file.rb @@ -47,7 +47,10 @@ def mount_uploadcare_file(attribute) Uploadcare::FileApi.delete_file(file_uuid) end - after_save "uploadcare_store_#{attribute}!".to_sym unless Uploadcare::Rails.configuration.do_not_store + unless Uploadcare::Rails.configuration.do_not_store + after_save "uploadcare_store_#{attribute}!".to_sym, if: "will_save_change_to_#{attribute}?".to_sym + end + return unless Uploadcare::Rails.configuration.delete_files_after_destroy after_destroy "uploadcare_delete_#{attribute}!".to_sym