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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php