1) The following query is really slow. What could be the reason? Propose some possible solutions. How to speed it up? Find all relations between tables base on the example code. If it requires, please rewrite the method.
def first_tag_history(tag, asin, marketplace_id)
TagHistory.joins(product_tag: { product: :account }).where("
product_tags.tag = :tag
AND tag_histories.created_at >= CURDATE()
AND products.asin = :asin
AND accounts.marketplace_id = :marketplace
", {