e94cd6fdfe
This commit adds a number of _html columns and, with the exception of Note, starts updating them whenever the content of their partner fields changes. Note has a collision with the note_html attr_accessor; that will be fixed later A background worker for clearing these cache columns is also introduced - use `rake cache:clear` to set it off. You can clear the database or Redis caches separately by running `rake cache:clear:db` or `rake cache:clear:redis`, respectively.
24 lines
490 B
Ruby
24 lines
490 B
Ruby
class GlobalLabel
|
|
attr_accessor :title, :labels
|
|
alias_attribute :name, :title
|
|
|
|
delegate :color, :description, to: :@first_label
|
|
|
|
def for_display
|
|
@first_label
|
|
end
|
|
|
|
def self.build_collection(labels)
|
|
labels = labels.group_by(&:title)
|
|
|
|
labels.map do |title, labels|
|
|
new(title, labels)
|
|
end
|
|
end
|
|
|
|
def initialize(title, labels)
|
|
@title = title
|
|
@labels = labels
|
|
@first_label = labels.find { |lbl| lbl.description.present? } || labels.first
|
|
end
|
|
end
|