Friday, October 28, 2011

Re: Slow reorder TreeBehaviour

Not a deja vu, just decided that will be much more comfortable to use a field with an order number and just once to click "Save order" than continuously clicking the moveDown or moveUp links until the desired position.
Will check the queries

On Fri, Oct 28, 2011 at 11:46 AM, AD7six <andydawson76@gmail.com> wrote:


On Oct 28, 10:09 am, "Constantin.FF" <constantin...@gmail.com> wrote:
> I need my tree sorted by each post sort value. Here is the function
> dealing with this. But it is executed extremely slow if some of the
> parents has more than 20-30 children
>
>         function _sortPosts($newSort){
>                         foreach ($newSort AS $id => $value) {
>                                 if(is_numeric($value['sort'])){
>                                         $this->Post->updateAll(array('Post.sort' => $value['sort']),
> array('Post.id' => $id));
>                                 } else {
>                                         $this->Session->setFlash(__('Non-numeric value given.', true),
> 'default', array('class' => 'error'));
>                                         $this->redirect($this->referer());
>                                 }
>
>                         }
>                         foreach(array_keys($this->data['Post']) as $parent){
>                                                 $this->Post->reorder(array('id' => $parent, 'field' =>
> 'Post.sort', 'order' => 'ASC', 'verify' => true));
>                         }

why are you (still? Or do I just have deja vu) using another field to
store the sort order - that's what lft is. if you _just_ call moveDown
on each post in the order you want them to appear the tree will be in
the order you expect.

>         }
>
> Example:
> 38 posts, 8 parents and 30 children
> 5518 queries took 6028 ms
> Page rendered in 20032ms.
>
> Is there some other way to do this reorder without such a delay?

The number of queries there most likely indicates an error in the tree
behavior (145 queries per post) - if you look at what those queries
are, you'll most likely be able to identify it and submit a pull
request.

AD

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: