Commit dde94a30

mo khan <mo@mokhan.ca>
2015-01-11 17:54:48
only load processed images.
1 parent 50eaeae
Changed files (3)
app
controllers
models
views
app/controllers/api/v2/cakes_controller.rb
@@ -10,6 +10,7 @@ module Api
 
       def index
         @cakes = paginate(repository.search_with(params).includes(:category))
+        @photos = Photo.processed.where(imageable_id: @cakes.pluck(:id))
       end
 
       def show(id = params[:id])
app/models/creation/repository.rb
@@ -1,7 +1,7 @@
 class Creation
   include Queryable
   scope :tagged, ->(tag) { tagged_with([tag]).where('photos_count > 0') }
-  scope :published, ->() { unscoped.distinct.includes(:user, :photos).joins(:photos).where('photos.image_processing' => nil) }
+  scope :published, ->{ joins(:photos).where(photos: { image_processing: nil }) }
   scope :search, ->(query) { where(["UPPER(creations.name) LIKE :query OR UPPER(creations.story) LIKE :query", { query: "%#{query.upcase}%" }]) }
 
   class Repository < SimpleDelegator
app/views/api/v2/cakes/index.json.jbuilder
@@ -4,7 +4,7 @@ end
 json.users @cakes.map(&:user) do |user|
   json.partial! user, user: user
 end
-json.photos @cakes.map(&:photos).flatten do |photo|
+json.photos @photos do |photo|
   json.partial! photo, photo: photo
 end
 json.categories @categories do |category|