Skip to content

Commit 6fd45da

Browse files
authored
Merge pull request #3718 from AlchemyCMS/backport/8.1-stable/pr-3712
[8.1-stable] Fix page cache flush not invalidating ETags
2 parents 8e48f3c + 316df8d commit 6fd45da

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

app/controllers/alchemy/admin/pages_controller.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,8 @@ def copy_language_tree
222222
end
223223

224224
def flush
225-
@current_language.pages.flushables.update_all(published_at: Time.current)
226-
# We need to ensure, that also all layoutpages get the +published_at+ timestamp set,
227-
# but not set to public true, because the cache_key for an element is +published_at+
228-
# and we don't want the layout pages to be present in +Page.published+ scope.
229-
@current_language.pages.flushable_layoutpages.update_all(published_at: Time.current)
225+
@current_language.pages.touch_all
226+
PageVersion.where(page_id: @current_language.pages.select(:id)).touch_all
230227
respond_to { |format| format.turbo_stream }
231228
end
232229

app/models/alchemy/page/page_scopes.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,6 @@ module PageScopes
7878
#
7979
scope :contentpages, -> { where(layoutpage: [false, nil]) }
8080

81-
# Returns all public contentpages that are not locked.
82-
#
83-
# Used for flushing all pages caches at once.
84-
#
85-
scope :flushables, -> { not_locked.published.contentpages }
86-
87-
# Returns all layoutpages that are not locked.
88-
#
89-
# Used for flushing all pages caches at once.
90-
#
91-
scope :flushable_layoutpages, -> { not_locked.layoutpages }
92-
9381
# All searchable pages
9482
#
9583
scope :searchables, -> { not_restricted.published.contentpages }

spec/requests/alchemy/admin/pages_controller_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,28 @@ 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 published_at field of content pages" do
128+
it "should update the updated_at field of content pages" do
129129
content_pages
130130

131131
travel_to(Time.current) do
132132
post flush_admin_pages_path, xhr: true
133-
# Reloading because published_at was directly updated in the database.
133+
# Reloading because updated_at was directly updated in the database.
134134
content_pages.map(&:reload)
135135
content_pages.each do |page|
136-
expect(page.published_at).to eq(Time.current)
136+
expect(page.updated_at).to eq(Time.current)
137137
end
138138
end
139139
end
140140

141-
it "should update the published_at field of layout pages" do
141+
it "should update the updated_at field of layout pages" do
142142
layout_pages
143143

144144
travel_to(Time.current) do
145145
post flush_admin_pages_path, xhr: true
146-
# Reloading because published_at was directly updated in the database.
146+
# Reloading because updated_at was directly updated in the database.
147147
layout_pages.map(&:reload)
148148
layout_pages.each do |page|
149-
expect(page.published_at).to eq(Time.current)
149+
expect(page.updated_at).to eq(Time.current)
150150
end
151151
end
152152
end

0 commit comments

Comments
 (0)