Skip to content

Commit 8a82ff6

Browse files
authored
Merge pull request #3722 from AlchemyCMS/backport/8.0-stable/pr-3720
[8.0-stable] fix(Page Cache Flushing): Only touch public page versions
2 parents 49a97bd + 16646fb commit 8a82ff6

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

app/controllers/alchemy/admin/pages_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ def copy_language_tree
217217
end
218218

219219
def flush
220-
@current_language.pages.touch_all
221-
PageVersion.where(page_id: @current_language.pages.select(:id)).touch_all
220+
PageVersion.where(page_id: @current_language.pages.select(:id)).published.touch_all
222221
respond_to { |format| format.js }
223222
end
224223

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
alchemy.flush_admin_pages_path,
2424
remote: true,
2525
method: :post,
26-
class: "icon_button please_wait",
27-
title: Alchemy.t("Flush page cache")
26+
class: "icon_button",
27+
title: Alchemy.t("Flush page cache"),
28+
"data-turbo-confirm": Alchemy.t(:confirm_to_flush_cache)
2829
) %>
2930
</sl-tooltip>
3031
</div>

config/locales/alchemy.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ en:
391391
confirm_to_delete_menu: "Do you really want to delete this menu?"
392392
confirm_to_delete_node: "Do you really want to delete this menu node?"
393393
confirm_to_delete_page: "Do you really want to delete this page?"
394+
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."
394395
ingredient_validations_headline: "Please check marked fields below"
395396
copy: "copy"
396397
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
@@ -227,29 +227,42 @@ module Alchemy
227227
let(:content_pages) { [content_page_1, content_page_2] }
228228
let(:layout_pages) { [layout_page_1, layout_page_2] }
229229

230-
it "should update the updated_at field of content pages" do
231-
content_pages
230+
it "should not update the updated_at field of pages" do
231+
pages = content_pages + layout_pages
232232

233233
travel_to(Time.current) do
234-
post flush_admin_pages_path, xhr: true
235-
# Reloading because updated_at was directly updated in the database.
236-
content_pages.map(&:reload)
237-
content_pages.each do |page|
238-
expect(page.updated_at).to eq(Time.current)
239-
end
234+
expect {
235+
post flush_admin_pages_path, xhr: true
236+
}.to_not change {
237+
# Reloading because updated_at was directly updated in the database.
238+
pages.map { _1.reload.updated_at }
239+
}
240240
end
241241
end
242242

243-
it "should update the updated_at field of layout pages" do
244-
layout_pages
243+
it "should update the updated_at field of public versions" do
244+
page_versions = content_pages.filter_map(&:public_version)
245245

246246
travel_to(Time.current) do
247-
post flush_admin_pages_path, xhr: true
248-
# Reloading because updated_at was directly updated in the database.
249-
layout_pages.map(&:reload)
250-
layout_pages.each do |page|
251-
expect(page.updated_at).to eq(Time.current)
252-
end
247+
expect {
248+
post flush_admin_pages_path, xhr: true
249+
}.to change {
250+
# Reloading because updated_at was directly updated in the database.
251+
page_versions.map { _1.reload.updated_at }
252+
}
253+
end
254+
end
255+
256+
it "should not update the updated_at field of draft versions" do
257+
page_versions = content_pages.filter_map(&:draft_version)
258+
259+
travel_to(Time.current) do
260+
expect {
261+
post flush_admin_pages_path, xhr: true
262+
}.to_not change {
263+
# Reloading because updated_at was directly updated in the database.
264+
page_versions.map { _1.reload.updated_at }
265+
}
253266
end
254267
end
255268
end

0 commit comments

Comments
 (0)