bundle exec rake algolia:reindex이 이 커밋 이후 더 이상 tag.topic_count가 없기 때문에 크래시가 발생합니다.
Clearing users from Algolia
Pushing users to Algolia
..
Successfully pushed 530 users to Algolia
Clearing tags from Algolia
Pushing tags to Algolia
rake aborted!
NoMethodError: undefined method `topic_count' for #<Tag id: 1, name: "installation", created_at: "2021-12-09 11:10:14.145911000 +0000", updated_at: "2021-12-09 11:10:14.145911000 +0000", pm_topic_count: 0, target_tag_id: nil, description: nil, public_topic_count: 3, staff_topic_count: 3>
Did you mean? pm_topic_count
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4.1/lib/active_model/attribute_methods.rb:458:in `method_missing'
/var/www/discourse/plugins/discourse-algolia/lib/discourse_algolia/tag_indexer.rb:18:in `should_index?'
/var/www/discourse/plugins/discourse-algolia/lib/discourse_algolia/indexer.rb:22:in `block in process!'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.1/lib/active_record/relation/batches.rb:71:in `each'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.1/lib/active_record/relation/batches.rb:71:in `block in find_each'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.1/lib/active_record/relation/batches.rb:138:in `block in find_in_batches
수동으로 staff_topic_count로 변경하면 문제가 해결되지만, 이로 인해 부수 효과가 있을 수 있을까요?
--- a/lib/discourse_algolia/tag_indexer.rb
+++ b/lib/discourse_algolia/tag_indexer.rb
@@ -15,10 +15,10 @@ class DiscourseAlgolia::TagIndexer < DiscourseAlgolia::Indexer
end
def should_index?(tag)
- @guardian.can_see?(tag) && tag.topic_count > 0
+ @guardian.can_see?(tag) && tag&.staff_topic_count > 0
end
def to_object(tag)
- { objectID: tag.id, url: tag.url, name: tag.name, topic_count: tag.topic_count }
+ { objectID: tag.id, url: tag.url, name: tag.name, topic_count: tag.staff_topic_count }
end
end