我正在使用Rails 5:
def index
@posts = Post.all
fresh_when(etag: @posts, last_modified: @posts.maximum(:updated_at))
end
这是Rails日志:
(1.0ms) SELECT MAX("posts"."updated_at") FROM "posts"
(0.7ms) SELECT COUNT(*) AS "size", MAX("posts"."updated_at") AS timestamp FROM "posts"
但如果我有这样的查询怎么办:
@posts = Post.includes(:comments).all
Rails的日志是:
Started GET "/posts"
Processing by PostsController#index as HTML
(0.2ms) SELECT MAX("posts"."updated_at") FROM "posts" LEFT OUTER JOIN "comments" ON "comments"."post_id" = "posts"."id"
(0.1ms) SELECT COUNT(*) AS "size", MAX("posts"."updated_at") AS timestamp FROM "posts"
但任何评论。事实上,如果我修改该帖子的一个评论和" updated_at"列更改它不会更新查询。
如何?
没有"包括(:评论)"一切都很好。