Skip to content

Commit ef12619

Browse files
committed
fix(Page Cache Flushing): Only touch public page versions
We must not touch the draft versions, as we compare the draft versions updated_at timestamp with the public version in order to find out if there are any unpublished changes. (cherry picked from commit a014db2) # Conflicts: # app/controllers/alchemy/admin/pages_controller.rb
1 parent 49a97bd commit ef12619

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
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

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)