9c76002bc1
Add `updatedAt` to stalled bubble options so JS can check if the card was recently updated, matching the `Card::Stallable#stalled?` logic. Refresh the bubble via Turbo Stream when a step is updated. This should have been part of #1625 Fixes https://app.fizzy.do/5986089/cards/3668
44 lines
1.3 KiB
Ruby
44 lines
1.3 KiB
Ruby
module Card::Stallable
|
|
extend ActiveSupport::Concern
|
|
|
|
STALLED_AFTER_LAST_SPIKE_PERIOD = 14.days
|
|
|
|
included do
|
|
has_one :activity_spike, class_name: "Card::ActivitySpike", dependent: :destroy
|
|
|
|
scope :with_activity_spikes, -> { joins(:activity_spike) }
|
|
scope :stalled, -> { open.active.with_activity_spikes.where(card_activity_spikes: { updated_at: ..STALLED_AFTER_LAST_SPIKE_PERIOD.ago }, updated_at: ..STALLED_AFTER_LAST_SPIKE_PERIOD.ago) }
|
|
|
|
before_update :remember_to_detect_activity_spikes
|
|
after_update_commit :detect_activity_spikes_later, if: :should_detect_activity_spikes?
|
|
end
|
|
|
|
# Keep in sync with #isStalled in app/javascript/controllers/bubble_controller.js
|
|
def stalled?
|
|
if activity_spike.present?
|
|
open? && last_activity_spike_at < STALLED_AFTER_LAST_SPIKE_PERIOD.ago && updated_at < STALLED_AFTER_LAST_SPIKE_PERIOD.ago
|
|
end
|
|
end
|
|
|
|
def last_activity_spike_at
|
|
activity_spike&.updated_at
|
|
end
|
|
|
|
def detect_activity_spikes
|
|
Card::ActivitySpike::Detector.new(self).detect
|
|
end
|
|
|
|
private
|
|
def remember_to_detect_activity_spikes
|
|
@should_detect_activity_spikes = published? && last_active_at_changed?
|
|
end
|
|
|
|
def should_detect_activity_spikes?
|
|
@should_detect_activity_spikes
|
|
end
|
|
|
|
def detect_activity_spikes_later
|
|
Card::ActivitySpike::DetectionJob.perform_later(self)
|
|
end
|
|
end
|