Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements #1121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/acts_as_taggable_on/taggable/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def set_tag_list_on(context, new_list)
end

def tagging_contexts
self.class.tag_types.map(&:to_s) + custom_contexts
(self.class.tag_types.map(&:to_s) + custom_contexts).uniq
end

def taggable_tenant
Expand Down
1 change: 1 addition & 0 deletions lib/acts_as_taggable_on/taggable/ownership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def reload(*args)
super(*args)
end

# This looks duplicated from taggable/core.rb
def save_owned_tags
tagging_contexts.each do |context|
cached_owned_tag_list_on(context).each do |owner, tag_list|
Expand Down
15 changes: 9 additions & 6 deletions lib/acts_as_taggable_on/tagging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ class Tagging < ActsAsTaggableOn.base_class.constantize # :nodoc:
private

def remove_unused_tags
if ActsAsTaggableOn.remove_unused_tags
if ActsAsTaggableOn.tags_counter
tag.destroy if tag.reload.taggings_count.zero?
elsif tag.reload.taggings.none?
tag.destroy
end
return unless ActsAsTaggableOn.remove_unused_tags

tag.reload if association(:tag).loaded?
if ActsAsTaggableOn.tags_counter
tag.destroy if tag.taggings_count.zero?
elsif tag.taggings.none?
# We already know there is no taggings, but the depended: :destroy will
# fire a query nonetheless, can we avoid it ?
tag.destroy
end
end
end
Expand Down