class Tags::Top
def call(limit: 20)
ActsAsTaggableOn::Tagging
.where(taggable_type: 'Snip')
.group(:tag_id)
.order(Arel.sql('COUNT(*) DESC'))
.limit(limit)
.count
end
end
Tagging systems can be expensive. For quick “top tags” features, compute from the join table with group and count. Avoid loading full taggable records.