# Sortables, acts\_as\_list and performance

**URL:** <https://www.ruby-forum.com/t/sortables-acts-as-list-and-performance/131433>\
**Category:** Rails\
**Created:** [March 10, 2008, 1:51am UTC](https://www.ruby-forum.com/t/sortables-acts-as-list-and-performance/131433 "2008-03-10T01:51:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mourner](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@mourner](https://www.ruby-forum.com/u/mourner)\
**Post date:** [March 10, 2008, 1:51am UTC](https://www.ruby-forum.com/t/sortables-acts-as-list-and-performance/131433/1 "2008-03-10T01:51:19Z")

</div>

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?
