summaryrefslogtreecommitdiff
path: root/app/services/projects/update_pages_configuration_service.rb
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-01-16 13:00:43 +0100
committerKamil Trzciński <ayufan@ayufan.eu>2019-01-16 13:02:41 +0100
commitebda58e817b843116a9e39ffcac05c9d5aa39535 (patch)
tree7e997eb284c7a863207844e028cb89a33a50f0de /app/services/projects/update_pages_configuration_service.rb
parent4ae4a4799e52f9382560388a3c08296f5e596db9 (diff)
downloadgitlab-ce-ebda58e817b843116a9e39ffcac05c9d5aa39535.tar.gz
Do not reload daemon if configuration file of pages does not change
Diffstat (limited to 'app/services/projects/update_pages_configuration_service.rb')
-rw-r--r--app/services/projects/update_pages_configuration_service.rb33
1 files changed, 18 insertions, 15 deletions
diff --git a/app/services/projects/update_pages_configuration_service.rb b/app/services/projects/update_pages_configuration_service.rb
index 43eb110c994..674071ad92a 100644
--- a/app/services/projects/update_pages_configuration_service.rb
+++ b/app/services/projects/update_pages_configuration_service.rb
@@ -2,6 +2,8 @@
module Projects
class UpdatePagesConfigurationService < BaseService
+ include Gitlab::Utils::StrongMemoize
+
attr_reader :project
def initialize(project)
@@ -9,17 +11,25 @@ module Projects
end
def execute
- if update_file(pages_config_file, pages_config.to_json)
- reload_daemon
+ if file_equals?(pages_config_file, pages_config_json)
+ return success(reload: false)
end
- success
+ update_file(pages_config_file, pages_config_json)
+ reload_daemon
+ success(reload: true)
rescue => e
error(e.message)
end
private
+ def pages_config_json
+ strong_memoize(:pages_config_json) do
+ pages_config.to_json
+ end
+ end
+
def pages_config
{
domains: pages_domains_config,
@@ -69,28 +79,21 @@ module Projects
end
def update_file(file, data)
- unless data
- FileUtils.remove(file, force: true)
- return true
- end
-
- existing_data = read_file(file)
- if data == existing_data
- return false
- end
-
temp_file = "#{file}.#{SecureRandom.hex(16)}"
File.open(temp_file, 'w') do |f|
f.write(data)
end
FileUtils.move(temp_file, file, force: true)
-
- true
ensure
# In case if the updating fails
FileUtils.remove(temp_file, force: true)
end
+ def file_equals?(file, data)
+ existing_data = read_file(file)
+ data == existing_data.to_s
+ end
+
def read_file(file)
File.open(file, 'r') do |f|
f.read