Skip to content

Commit a014db2

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.
1 parent f28844f commit a014db2

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
@@ -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

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)