0
我想加快我的查询速度,我没有在我的表上做任何索引。是一种类似'子弹'的宝石,它可以自动检测您的查询性能,并建议您在某些特定列上添加索引
但我不知道应该把索引放在正确的位置。
控制器
def search
@rooms = Room.includes(:hotel, :skus).where(id: available_rooms_ids)
end
JSON建设者
我的JSON建设者是一种复杂的。
孩子需要获取其父数据。
专利还需要获取其子数据。
他们的关系链看起来像
- 酒店HAS_MANY房
- 房HAS_MANY RoomSku
- RoomSku HAS_MANY STOCK
CODE
json.array!(@rooms) do |item|
json.merge! item.attributes
json.hotel item.hotel
json.room_skus do
json.array! item.skus do |sku|
next if (sku.date < @check_in_time.to_date or sku.date > @check_out_time.to_date)
json.merge! sku.attributes.merge({stock:sku.stock})
end
end
json.img_src_url item.hotel.images.last.src.url
end
end