Closed dpaluy closed 4 years ago
Looks like it is impossible without patching acts_as_taggable_on/taggable/core.rb:
require_relative 'tagged_with_query'
module ActsAsTaggableOn::Taggable
module Core
def self.included(base)
base.extend ActsAsTaggableOn::Taggable::Core::ClassMethods
base.class_eval do
attr_writer :custom_contexts
after_save :save_tags
end
...
def save_tags
tagging_contexts.each do |context|
next unless tag_list_cache_set_on(context)
# List of currently assigned tag names
tag_list = tag_list_cache_on(context).uniq
# Find existing tags or create non-existing tags:
tags = find_or_create_tags_from_list_with_context(tag_list, context)
...
lib/acts_as_taggable_on/taggable/ownership.rb:
module ActsAsTaggableOn::Taggable
module Ownership
def self.included(base)
base.extend ActsAsTaggableOn::Taggable::Ownership::ClassMethods
base.class_eval do
after_save :save_owned_tags
end
...
def save_owned_tags
tagging_contexts.each do |context|
cached_owned_tag_list_on(context).each do |owner, tag_list|
...
save_tags and save_owned_tags always gets triggered to load tags unnecessarily.
My class has several
acts_as_taggable_on
. Each update to the record, triggersActsAsTaggableOn::Tag Load
query after updateExample:
How to avoid those Tag load queries?