-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Improving Performance of Tags #1076
Comments
Just pinging on this question again... My main question is about tags on existing records. Our application is multi-tenant in the same DB. There is an accounts table and a contacts table. The contacts table has an account_id column. If I add |
Hello @bradeaton i know this is old post but anyway, our team also use this gem for tagging conversation rooms in our application. There is one heavy query that do aggregates on our model (rooms count by tag). This query can process up to 8 millions row at once so itu is very slow before optimi zed (~30s) and now it becomes ~5s. My comments on your query is:
|
I faced the almost same problem. It seems the best way is to create a new column on the table and store the cached tag. And query on that table not using these tables. (Ref: https://github.com/mbleigh/acts-as-taggable-on/wiki/Caching I'm testing with my local, hope this works. |
Another solution is to add a new scope that reproduces the original query, eg
and then replace the It would be nice to add the option of passing in an actual tag (instead of the name) and then use the query in the scope above. |
We have an application that makes extensive use of tags across many different models. We just recently upgraded our application to Rails 6.1 and acts-as-taggable 9.0.1. New Relic transaction traces are showing significant time spent these queries:
1,400ms on this one:
SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $? AND "taggings"."taggable_type" = $? AND (taggings.context = ? AND taggings.tagger_id IS ?)
425ms on this one:
SELECT "taggings".* FROM "taggings" WHERE "taggings"."taggable_id" = $? AND "taggings"."taggable_type" = $?
Here's what our indexes look like right now:
We're looking for ways to speed these up. Our application is multi-tenant within the same database. All our model classes are scoped on an account_id field. If we add
acts_as_taggable_tenant :account_id
on each of these models, is there some migration that we need to do for all the existing taggings?Are there other things that are suggested to speed things up?
The text was updated successfully, but these errors were encountered: