> Rails does not (cannot) add indexes to your database.
Am I missing something in this sentence? You can add indexes in migrations.
Am I missing something in this sentence? You can add indexes in migrations.
photos_i_am_in = user.friends.map {|f| f.photos.select {|p| p.include? user}}.flatten
(Code somewhat minimalist - don't think too hard about it.)
As mickeyben says above, choosing indexes is a compromise - you sacrifice performance in one area for performance in another. Only you can make the right decision there, because only you can begin to know how the app will be used in production.