implications: remove memoization of parents, descendants, forum_updater.
Not necessary for performance and flushing the cache at the right times added some complexity.
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
class TagImplication < TagRelationship
|
class TagImplication < TagRelationship
|
||||||
extend Memoist
|
|
||||||
|
|
||||||
array_attribute :descendant_names
|
array_attribute :descendant_names
|
||||||
|
|
||||||
|
has_many :child_implications, class_name: "TagImplication", primary_key: :consequent_name, foreign_key: :antecedent_name
|
||||||
|
has_many :parent_implications, class_name: "TagImplication", primary_key: :antecedent_name, foreign_key: :consequent_name
|
||||||
|
|
||||||
before_save :update_descendant_names
|
before_save :update_descendant_names
|
||||||
after_save :update_descendant_names_for_parents
|
after_save :update_descendant_names_for_parents
|
||||||
after_destroy :update_descendant_names_for_parents
|
after_destroy :update_descendant_names_for_parents
|
||||||
@@ -16,7 +17,6 @@ class TagImplication < TagRelationship
|
|||||||
|
|
||||||
module DescendantMethods
|
module DescendantMethods
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
extend Memoist
|
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# assumes names are normalized
|
# assumes names are normalized
|
||||||
@@ -43,35 +43,24 @@ class TagImplication < TagRelationship
|
|||||||
end
|
end
|
||||||
end.sort.uniq
|
end.sort.uniq
|
||||||
end
|
end
|
||||||
memoize :descendants
|
|
||||||
|
|
||||||
def update_descendant_names
|
def update_descendant_names
|
||||||
self.descendant_names = descendants
|
self.descendant_names = descendants
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_descendant_names!
|
def update_descendant_names!
|
||||||
flush_cache
|
|
||||||
update_descendant_names
|
update_descendant_names
|
||||||
update_attribute(:descendant_names, descendant_names)
|
update_attribute(:descendant_names, descendant_names)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_descendant_names_for_parents
|
def update_descendant_names_for_parents
|
||||||
parents.each do |parent|
|
parent_implications.each do |parent|
|
||||||
parent.update_descendant_names!
|
parent.update_descendant_names!
|
||||||
parent.update_descendant_names_for_parents
|
parent.update_descendant_names_for_parents
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module ParentMethods
|
|
||||||
extend Memoist
|
|
||||||
|
|
||||||
def parents
|
|
||||||
self.class.where("consequent_name = ?", antecedent_name)
|
|
||||||
end
|
|
||||||
memoize :parents
|
|
||||||
end
|
|
||||||
|
|
||||||
module ValidationMethods
|
module ValidationMethods
|
||||||
def absence_of_circular_relation
|
def absence_of_circular_relation
|
||||||
return if is_rejected?
|
return if is_rejected?
|
||||||
@@ -124,8 +113,6 @@ class TagImplication < TagRelationship
|
|||||||
end
|
end
|
||||||
|
|
||||||
module ApprovalMethods
|
module ApprovalMethods
|
||||||
extend Memoist
|
|
||||||
|
|
||||||
def process!(update_topic: true)
|
def process!(update_topic: true)
|
||||||
unless valid?
|
unless valid?
|
||||||
raise errors.full_messages.join("; ")
|
raise errors.full_messages.join("; ")
|
||||||
@@ -183,16 +170,9 @@ class TagImplication < TagRelationship
|
|||||||
skip_update: !TagRelationship::SUPPORT_HARD_CODED
|
skip_update: !TagRelationship::SUPPORT_HARD_CODED
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
memoize :forum_updater
|
|
||||||
end
|
end
|
||||||
|
|
||||||
include DescendantMethods
|
include DescendantMethods
|
||||||
include ParentMethods
|
|
||||||
include ValidationMethods
|
include ValidationMethods
|
||||||
include ApprovalMethods
|
include ApprovalMethods
|
||||||
|
|
||||||
def reload(options = {})
|
|
||||||
flush_cache
|
|
||||||
super
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user