To avoid timeouts caused by excessive data
This commit is contained in:
parent
f335afb861
commit
df13ec28e2
|
|
@ -21,34 +21,46 @@ class Admin::ImagesController < OrbitAdminController
|
|||
@images = @album.album_images.asc(:order)
|
||||
end
|
||||
|
||||
def changeorder
|
||||
type = params[:type]
|
||||
if type == "imgholder"
|
||||
album = Album.find(params[:album_id]) rescue nil
|
||||
images = params[:imageids]
|
||||
images.each_with_index.reverse_each do |image, i|
|
||||
img = AlbumImage.find(image) rescue nil
|
||||
if !img.nil?
|
||||
img.order = i
|
||||
img.save
|
||||
end
|
||||
end
|
||||
if album
|
||||
album.update(:min_order=>-1)
|
||||
end
|
||||
elsif type == "orbit_gallery"
|
||||
albums = params[:imageids]
|
||||
albums.each_with_index.reverse_each do |albumid, i|
|
||||
album = Album.find(albumid) rescue nil
|
||||
if !album.nil?
|
||||
album.order = i
|
||||
album.save
|
||||
end
|
||||
end
|
||||
AlbumSetting.update_all(:min_order=>-1)
|
||||
end
|
||||
render :json => {"success" => true}.to_json
|
||||
end
|
||||
def changeorder
|
||||
type = params[:type]
|
||||
if type == "imgholder"
|
||||
album = Album.find(params[:album_id]) rescue nil
|
||||
images = params[:imageids]
|
||||
operations = []
|
||||
images.each_with_index.reverse_each do |image, i|
|
||||
next if image.blank?
|
||||
oid = begin; BSON::ObjectId(image); rescue; nil; end
|
||||
next if oid.nil?
|
||||
operations << {
|
||||
update_one: {
|
||||
filter: { _id: oid },
|
||||
update: { "$set" => { order: i } }
|
||||
}
|
||||
}
|
||||
end
|
||||
AlbumImage.collection.bulk_write(operations) if operations.any?
|
||||
if album
|
||||
album.update(:min_order=>-1)
|
||||
end
|
||||
elsif type == "orbit_gallery"
|
||||
albums = params[:imageids]
|
||||
operations = []
|
||||
albums.each_with_index.reverse_each do |albumid, i|
|
||||
next if albumid.blank?
|
||||
oid = begin; BSON::ObjectId(albumid); rescue; nil; end
|
||||
next if oid.nil?
|
||||
operations << {
|
||||
update_one: {
|
||||
filter: { _id: oid },
|
||||
update: { "$set" => { order: i } }
|
||||
}
|
||||
}
|
||||
end
|
||||
Album.collection.bulk_write(operations) if operations.any?
|
||||
AlbumSetting.update_all(:min_order=>-1)
|
||||
end
|
||||
render :json => {"success" => true}.to_json
|
||||
end
|
||||
|
||||
def delete_photos
|
||||
images = params['images']
|
||||
|
|
|
|||
Loading…
Reference in New Issue