Columns touch the cards when the name/color changes
This commit is contained in:
@@ -3,6 +3,6 @@ class Collections::Columns::ClosedsController < ApplicationController
|
||||
|
||||
def show
|
||||
set_page_and_extract_portion_from @collection.cards.closed.recently_closed_first
|
||||
cards_fresh_when @page.records
|
||||
fresh_when @page.records
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,6 @@ class Collections::Columns::NotNowsController < ApplicationController
|
||||
|
||||
def show
|
||||
set_page_and_extract_portion_from @collection.cards.postponed.reverse_chronologically.with_golden_first
|
||||
cards_fresh_when @page.records
|
||||
fresh_when @page.records
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,6 @@ class Collections::Columns::StreamsController < ApplicationController
|
||||
|
||||
def show
|
||||
set_page_and_extract_portion_from @collection.cards.awaiting_triage.by_last_activity.with_golden_first
|
||||
cards_fresh_when @page.records
|
||||
fresh_when @page.records
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ class Collections::ColumnsController < ApplicationController
|
||||
|
||||
def show
|
||||
set_page_and_extract_portion_from @column.cards.active.by_last_activity.with_golden_first
|
||||
cards_fresh_when @page.records
|
||||
fresh_when @page.records
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -9,8 +9,4 @@ module CollectionScoped
|
||||
def set_collection
|
||||
@collection = Current.user.collections.find(params[:collection_id])
|
||||
end
|
||||
|
||||
def cards_fresh_when(cards)
|
||||
fresh_when etag: [ cards, @collection.entropy_configuration, @collection.columns.all ]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -48,6 +48,6 @@ module CardsHelper
|
||||
end
|
||||
|
||||
def card_preview_cache_parts(card)
|
||||
[ card, card.collection.entropy_configuration, card.collection.publication, card.column ]
|
||||
[ card, card.collection.entropy_configuration ]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Card::TouchAllJob < ApplicationJob
|
||||
queue_as :backend
|
||||
|
||||
def perform(container)
|
||||
container.cards.in_batches(&:touch_all)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
module Collection::Cards
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_many :cards, dependent: :destroy
|
||||
|
||||
after_update_commit :touch_all_cards_later, if: :saved_change_to_name?
|
||||
end
|
||||
|
||||
def touch_all_cards_later
|
||||
Card::TouchAllJob.perform_later(self)
|
||||
end
|
||||
end
|
||||
@@ -8,9 +8,18 @@ class Column < ApplicationRecord
|
||||
validates :color, presence: true
|
||||
|
||||
before_validation :set_default_color
|
||||
after_save_commit :touch_all_cards_later, if: :should_invalidate_cards?
|
||||
|
||||
private
|
||||
def set_default_color
|
||||
self.color ||= Card::DEFAULT_COLOR
|
||||
end
|
||||
|
||||
def touch_all_cards_later
|
||||
Card::TouchAllJob.perform_later(self)
|
||||
end
|
||||
|
||||
def should_invalidate_cards?
|
||||
saved_change_to_name? || saved_change_to_color?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
require "test_helper"
|
||||
|
||||
class Collection::CardsTest < ActiveSupport::TestCase
|
||||
test "touch cards when the name changes" do
|
||||
collection = collections(:writebook)
|
||||
|
||||
assert_enqueued_with(job: Card::TouchAllJob) do
|
||||
collection.update!(name: "New Name")
|
||||
end
|
||||
|
||||
assert_no_enqueued_jobs(only: Card::TouchAllJob) do
|
||||
collection.update!(updated_at: 1.hour.from_now)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,4 +6,20 @@ class ColumnTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal Card::DEFAULT_COLOR, column.color
|
||||
end
|
||||
|
||||
test "touch all the cards when the name or color changes" do
|
||||
column = columns(:writebook_triage)
|
||||
|
||||
assert_enqueued_with(job: Card::TouchAllJob) do
|
||||
column.update!(name: "New Name")
|
||||
end
|
||||
|
||||
assert_enqueued_with(job: Card::TouchAllJob) do
|
||||
column.update!(color: "#FF0000")
|
||||
end
|
||||
|
||||
assert_no_enqueued_jobs(only: Card::TouchAllJob) do
|
||||
column.update!(updated_at: 1.hour.from_now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user