Read more

ActsAsTaggableOn: Cache tag lists

Tobias Kraze
November 25, 2011Software engineer at makandra GmbH

For performance improvements (and to remove the need for eager loading), the ActsAsTaggableOn gem Show archive.org snapshot supports caching your tag lists directly in your model. To enable this, simply add a cached_tag_list column to your table.

Example:

class Company < ActiveRecord::Base
  acts_as_taggable_on :categories
end
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

The cache column has to be named cached_category_list.

Existing data

If you already have existing data, you have to save all records with tags once, after you've added the column, like this:

Company.all.each do |company|
  company.category_list # it seems you need to do this first to generate the list
  company.save!
end
Posted by Tobias Kraze to makandra dev (2011-11-25 10:29)