{"action":"closed","issue":{"url":"https://api.github.com/repos/nesquena/rabl/issues/603","labels_url":"https://api.github.com/repos/nesquena/rabl/issues/603/labels{/name}","comments_url":"https://api.github.com/repos/nesquena/rabl/issues/603/comments","events_url":"https://api.github.com/repos/nesquena/rabl/issues/603/events","html_url":"https://github.com/nesquena/rabl/issues/603","id":51449689,"number":603,"title":"Rabl eager loads collection even in the case of a cache hit","user":{"login":"rhomeister","id":1710924,"avatar_url":"https://avatars.githubusercontent.com/u/1710924?v=3","gravatar_id":"","url":"https://api.github.com/users/rhomeister","html_url":"https://github.com/rhomeister","followers_url":"https://api.github.com/users/rhomeister/followers","following_url":"https://api.github.com/users/rhomeister/following{/other_user}","gists_url":"https://api.github.com/users/rhomeister/gists{/gist_id}","starred_url":"https://api.github.com/users/rhomeister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhomeister/subscriptions","organizations_url":"https://api.github.com/users/rhomeister/orgs","repos_url":"https://api.github.com/users/rhomeister/repos","events_url":"https://api.github.com/users/rhomeister/events{/privacy}","received_events_url":"https://api.github.com/users/rhomeister/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2014-12-09T16:37:50Z","updated_at":"2015-01-19T16:14:14Z","closed_at":"2015-01-19T16:14:14Z","body":"Rabl seems to eager load the `collection` regardless of whether there is a cache hit or whether the actual collection is needed to generate the cache key.\r\n\r\nTo reproduce this issue, here is a bare bones controller and view:\r\n\r\nController: \r\n\r\n```\r\nclass UsersController < ApplicationController\r\n    def index\r\n      @users = User.limit(10)\r\n      puts \"========end of controller============\"\r\n    end\r\nend\r\n```\r\n\r\nView: \r\n\r\n```\r\ncache \"static cache key\", expires_in: 1.day\r\ncollection @users\r\nattributes :id\r\n```\r\n\r\nResult in logs:\r\n\r\n```\r\n========end of controller============\r\n  User Load (0.7ms)  SELECT \"users\".* FROM \"users\" LIMIT 10\r\nCache read: rabl/static cache key//json/0177dcab54eb3e18d7e976b32808d46a ({:expires_in=>1 day})\r\nCache fetch_hit: rabl/static cache key//json/0177dcab54eb3e18d7e976b32808d46a ({:expires_in=>1 day})\r\n```\r\n\r\nConclusion, even when the cache key is a simple static string and there is a cache hit, the collection of users is still loaded. Obviously, this is a very simple example, but if the collection contains many includes and/or complex queries, this results in a huge performance hit because objects are needlessly loaded into memory."}}