Hi!
I have a reordering feature for one of my models. It’s done with
Sortables JS component that sends an Ajax request with a hash of new
positions for each item after reordering, with the following action
that processes it:
def reorder
params[:pos].each do |id, pos|
@user.activities.find(id).insert_at(pos)
end
head :ok
end
I’m using acts_as_list to recalculate positions.
Everything works, but I have a problem: for EVERY activity that was
moved there are 5 requests to the database (1 select and 4 updates,
which in their turn are quite CPU-intensive because position
recalculation involves updating most of the list items).
Did someone solve a similar problem? Any advices on making reordering
not so resource-hungry and slow?