nesquena / rabl

General ruby templating with json, bson, xml, plist and msgpack support
http://blog.codepath.com/2011/06/27/building-a-platform-api-on-rails/
MIT License
3.64k stars 334 forks source link

No way to access cache key from controller #631

Open leei opened 9 years ago

leei commented 9 years ago

For some very rich models I have I want to be able to check the RABL cache keys from the controller and only eager load related models when necessary. The following pseudo-code is the basic idea, and the problem is the fragment_exists? call. What can I use to see whether the RABL cached value is there?

ids = {}
models = Model.all.to_a
models.each_with_index do |m|
  if !fragment_exists?(m)
    ids[m.id] = i
  end
end
Model.includes(:related1, :related2).where(id: ids.keys).each do |m|
  models[ids[m.id]] = m
end unless ids.empty?
@models = models
render "models/index"