Skip to content

Commit 295bc35

Browse files
author
Marc Antwertinger
committed
Fix page cache flush not invalidating ETags
(cherry picked from commit 0bb499f) # Conflicts: # app/controllers/alchemy/admin/pages_controller.rb
1 parent 3d6879c commit 295bc35

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
@@ -217,11 +217,8 @@ def copy_language_tree
217217
end
218218

219219
def flush
220-
@current_language.pages.flushables.update_all(published_at: Time.current)
221-
# We need to ensure, that also all layoutpages get the +published_at+ timestamp set,
222-
# but not set to public true, because the cache_key for an element is +published_at+
223-
# and we don't want the layout pages to be present in +Page.published+ scope.
224-
@current_language.pages.flushable_layoutpages.update_all(published_at: Time.current)
220+
@current_language.pages.touch_all
221+
PageVersion.where(page_id: @current_language.pages.select(:id)).touch_all
225222
respond_to { |format| format.js }
226223
end
227224

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
@@ -227,28 +227,28 @@ 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 published_at field of content pages" do
230+
it "should update the updated_at field of content pages" do
231231
content_pages
232232

233233
travel_to(Time.current) do
234234
post flush_admin_pages_path, xhr: true
235-
# Reloading because published_at was directly updated in the database.
235+
# Reloading because updated_at was directly updated in the database.
236236
content_pages.map(&:reload)
237237
content_pages.each do |page|
238-
expect(page.published_at).to eq(Time.current)
238+
expect(page.updated_at).to eq(Time.current)
239239
end
240240
end
241241
end
242242

243-
it "should update the published_at field of layout pages" do
243+
it "should update the updated_at field of layout pages" do
244244
layout_pages
245245

246246
travel_to(Time.current) do
247247
post flush_admin_pages_path, xhr: true
248-
# Reloading because published_at was directly updated in the database.
248+
# Reloading because updated_at was directly updated in the database.
249249
layout_pages.map(&:reload)
250250
layout_pages.each do |page|
251-
expect(page.published_at).to eq(Time.current)
251+
expect(page.updated_at).to eq(Time.current)
252252
end
253253
end
254254
end

0 commit comments

Comments
 (0)