mbleigh / acts-as-taggable-on

A tagging plugin for Rails applications that allows for custom tagging along dynamic contexts.
http://mbleigh.lighthouseapp.com/projects/10116-acts-as-taggable-on
MIT License
4.96k stars 1.19k forks source link

Use none? instead of count.zero? #1030

Closed gr-eg closed 3 years ago

gr-eg commented 3 years ago

We have run in to a performance issue when removing unused tags and not using the tags_counter

taggings.count.zero? executes the following sql

`SELECT COUNT(*) FROM taggings WHERE taggings.tag_id = ?`

This can be very slow on large tables

by using taggings.none? it instead executes:

`SELECT 1 AS one FROM taggings WHERE taggings.tag_id = 304185392 LIMIT 1`

which can always use the index and is much faster.

seuros commented 3 years ago

released