Skip to content

Commit ecab477

Browse files
authored
Merge pull request #3720 from AlchemyCMS/fix-page-cache-flushing
fix(Page Cache Flushing): Only touch public page versions
2 parents f28844f + ba4f133 commit ecab477

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

app/controllers/alchemy/admin/pages_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ def copy_language_tree
222222
end
223223

224224
def flush
225-
@current_language.pages.touch_all
226-
PageVersion.where(page_id: @current_language.pages.select(:id)).touch_all
225+
PageVersion.where(page_id: @current_language.pages.select(:id)).published.touch_all
227226
respond_to { |format| format.turbo_stream }
228227
end
229228

app/views/alchemy/admin/pages/_toolbar.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<%= button_to(
2222
render_icon(:eraser),
2323
alchemy.flush_admin_pages_path,
24-
"turbo-method": :post,
25-
class: "icon_button please_wait"
24+
"data-turbo-confirm": Alchemy.t(:confirm_to_flush_cache),
25+
class: "icon_button"
2626
) %>
2727
</sl-tooltip>
2828
</div>

config/locales/alchemy.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ en:
399399
confirm_to_delete_menu: "Do you really want to delete this menu?"
400400
confirm_to_delete_node: "Do you really want to delete this menu node?"
401401
confirm_to_delete_page: "Do you really want to delete this page?"
402+
confirm_to_flush_cache: "Do you really want to flush the page cache? This will might take a while and can make first page requests slow."
402403
ingredient_validations_headline: "Please check marked fields below"
403404
copy: "copy"
404405
copy_element: "Copy this element"

spec/requests/alchemy/admin/pages_controller_spec.rb

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,42 @@ module Alchemy
125125
let(:content_pages) { [content_page_1, content_page_2] }
126126
let(:layout_pages) { [layout_page_1, layout_page_2] }
127127

128-
it "should update the updated_at field of content pages" do
129-
content_pages
128+
it "should not update the updated_at field of pages" do
129+
pages = content_pages + layout_pages
130130

131131
travel_to(Time.current) do
132-
post flush_admin_pages_path, xhr: true
133-
# Reloading because updated_at was directly updated in the database.
134-
content_pages.map(&:reload)
135-
content_pages.each do |page|
136-
expect(page.updated_at).to eq(Time.current)
137-
end
132+
expect {
133+
post flush_admin_pages_path, xhr: true
134+
}.to_not change {
135+
# Reloading because updated_at was directly updated in the database.
136+
pages.map { _1.reload.updated_at }
137+
}
138138
end
139139
end
140140

141-
it "should update the updated_at field of layout pages" do
142-
layout_pages
141+
it "should update the updated_at field of public versions" do
142+
page_versions = content_pages.map(&:public_version)
143143

144144
travel_to(Time.current) do
145-
post flush_admin_pages_path, xhr: true
146-
# Reloading because updated_at was directly updated in the database.
147-
layout_pages.map(&:reload)
148-
layout_pages.each do |page|
149-
expect(page.updated_at).to eq(Time.current)
150-
end
145+
expect {
146+
post flush_admin_pages_path, xhr: true
147+
}.to change {
148+
# Reloading because updated_at was directly updated in the database.
149+
page_versions.map { _1.reload.updated_at }
150+
}
151+
end
152+
end
153+
154+
it "should not update the updated_at field of draft versions" do
155+
page_versions = content_pages.map(&:draft_version)
156+
157+
travel_to(Time.current) do
158+
expect {
159+
post flush_admin_pages_path, xhr: true
160+
}.to_not change {
161+
# Reloading because updated_at was directly updated in the database.
162+
page_versions.map { _1.reload.updated_at }
163+
}
151164
end
152165
end
153166
end

0 commit comments

Comments
 (0)