Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ebda58e8
Commit
ebda58e8
authored
Jan 16, 2019
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not reload daemon if configuration file of pages does not change
parent
4ae4a479
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
22 deletions
+48
-22
app/services/projects/update_pages_configuration_service.rb
app/services/projects/update_pages_configuration_service.rb
+18
-15
changelogs/unreleased/update-pages-config-only-when-changed.yml
...logs/unreleased/update-pages-config-only-when-changed.yml
+5
-0
spec/services/projects/update_pages_configuration_service_spec.rb
...vices/projects/update_pages_configuration_service_spec.rb
+25
-7
No files found.
app/services/projects/update_pages_configuration_service.rb
View file @
ebda58e8
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
module
Projects
module
Projects
class
UpdatePagesConfigurationService
<
BaseService
class
UpdatePagesConfigurationService
<
BaseService
include
Gitlab
::
Utils
::
StrongMemoize
attr_reader
:project
attr_reader
:project
def
initialize
(
project
)
def
initialize
(
project
)
...
@@ -9,17 +11,25 @@ module Projects
...
@@ -9,17 +11,25 @@ module Projects
end
end
def
execute
def
execute
if
update_file
(
pages_config_file
,
pages_config
.
to
_json
)
if
file_equals?
(
pages_config_file
,
pages_config
_json
)
re
load_daemon
re
turn
success
(
reload:
false
)
end
end
success
update_file
(
pages_config_file
,
pages_config_json
)
reload_daemon
success
(
reload:
true
)
rescue
=>
e
rescue
=>
e
error
(
e
.
message
)
error
(
e
.
message
)
end
end
private
private
def
pages_config_json
strong_memoize
(
:pages_config_json
)
do
pages_config
.
to_json
end
end
def
pages_config
def
pages_config
{
{
domains:
pages_domains_config
,
domains:
pages_domains_config
,
...
@@ -69,28 +79,21 @@ module Projects
...
@@ -69,28 +79,21 @@ module Projects
end
end
def
update_file
(
file
,
data
)
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
)
}
"
temp_file
=
"
#{
file
}
.
#{
SecureRandom
.
hex
(
16
)
}
"
File
.
open
(
temp_file
,
'w'
)
do
|
f
|
File
.
open
(
temp_file
,
'w'
)
do
|
f
|
f
.
write
(
data
)
f
.
write
(
data
)
end
end
FileUtils
.
move
(
temp_file
,
file
,
force:
true
)
FileUtils
.
move
(
temp_file
,
file
,
force:
true
)
true
ensure
ensure
# In case if the updating fails
# In case if the updating fails
FileUtils
.
remove
(
temp_file
,
force:
true
)
FileUtils
.
remove
(
temp_file
,
force:
true
)
end
end
def
file_equals?
(
file
,
data
)
existing_data
=
read_file
(
file
)
data
==
existing_data
.
to_s
end
def
read_file
(
file
)
def
read_file
(
file
)
File
.
open
(
file
,
'r'
)
do
|
f
|
File
.
open
(
file
,
'r'
)
do
|
f
|
f
.
read
f
.
read
...
...
changelogs/unreleased/update-pages-config-only-when-changed.yml
0 → 100644
View file @
ebda58e8
---
title
:
Do not reload daemon if configuration file of pages does not change
merge_request
:
author
:
type
:
performance
spec/services/projects/update_pages_configuration_service_spec.rb
View file @
ebda58e8
...
@@ -2,23 +2,41 @@ require 'spec_helper'
...
@@ -2,23 +2,41 @@ require 'spec_helper'
describe
Projects
::
UpdatePagesConfigurationService
do
describe
Projects
::
UpdatePagesConfigurationService
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
subject
{
described_class
.
new
(
project
)
}
let
(
:service
)
{
described_class
.
new
(
project
)
}
describe
"#update"
do
describe
"#update"
do
let
(
:file
)
{
Tempfile
.
new
(
'pages-test'
)
}
let
(
:file
)
{
Tempfile
.
new
(
'pages-test'
)
}
subject
{
service
.
execute
}
after
do
after
do
file
.
close
file
.
close
file
.
unlink
file
.
unlink
end
end
it
'updates the .update file'
do
before
do
# Access this reference to ensure scoping works
allow
(
service
).
to
receive
(
:pages_config_file
).
and_return
(
file
.
path
)
Projects
::
Settings
# rubocop:disable Lint/Void
end
expect
(
subject
).
to
receive
(
:pages_config_file
).
and_return
(
file
.
path
)
expect
(
subject
).
to
receive
(
:reload_daemon
).
and_call_original
context
'when configuration changes'
do
it
'updates the .update file'
do
expect
(
service
).
to
receive
(
:reload_daemon
).
and_call_original
expect
(
subject
).
to
include
(
status: :success
,
reload:
true
)
end
end
context
'when configuration does not change'
do
before
do
# we set the configuration
service
.
execute
end
it
'does not update the .update file'
do
expect
(
service
).
not_to
receive
(
:reload_daemon
)
expect
(
subject
.
execute
).
to
eq
({
status: :success
})
expect
(
subject
).
to
include
(
status: :success
,
reload:
false
)
end
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment