leoric Posted May 12, 2014 Share Posted May 12, 2014 hi,everyone: i have a problem. there are currently 1700 pages in my site (it have a continual trend of increases...) and now the problem is : create a new page need a long time , more than 15 seconds. whether via api or back end. the details(such as in the back end page tree create new page, any parent): when i click "new" then i have to waiting for more than 15 seconds ... after a long waiting i will see " add new " page form.( title, name and template select..) what is the problem? Link to comment Share on other sites More sharing options...
Pete Posted May 12, 2014 Share Posted May 12, 2014 Are you using repeaters in the template for the page you are trying to add? Or is this just at the stage where you enter a page title before going to the main page editing form? Link to comment Share on other sites More sharing options...
leoric Posted May 13, 2014 Author Share Posted May 13, 2014 Are you using repeaters in the template for the page you are trying to add? Or is this just at the stage where you enter a page title before going to the main page editing form? hi, pete thank you for your reply. finally i found the cause of this problem. this code spent too much time to execute.. $id=$this->pages->find("include=all")->last()->id+1; Is there a way to replace this? here is full code in the module: public function hookRender(HookEvent $event) { if($this->process != 'ProcessPageAdd') return; $id=$this->pages->find("include=all")->last()->id+1; //get the latest id $inputfield = $event->object; if(strlen($inputfield->attr('value'))) return; $inputfield->attr('value', $id); } Link to comment Share on other sites More sharing options...
leoric Posted May 13, 2014 Author Share Posted May 13, 2014 $id=$this->pages->find("include=all,sort=-id,limit=1")->first()+1; i use this instead of $id=$this->pages->find("include=all")->last()->id+1; is it ok? Link to comment Share on other sites More sharing options...
adrian Posted May 13, 2014 Share Posted May 13, 2014 I don't actually see how your revised find would work, but this will: $id = $this->pages->get("include=all, sort=-id")->id + 1; 3 Link to comment Share on other sites More sharing options...
owzim Posted May 13, 2014 Share Posted May 13, 2014 $id = $this->pages->get("include=all, sort=-id")->id + 1; Great solution adrian, I'll try to explain why this is faster than leoric's method and how both work, for people who don't know: $pages->find("include=all"); ... will fetch ALL pages, which means PW is creating objects/instances for every single page that is fetched, which is very expensive. $pages->get("include=all, sort=-id"); ... on the other hand will only fetch ONE page and therefore only create only ONE Page instance for that query. The sort=-id will take care of an descending sort order by id, so the last added page will be returned. What I am wondering though is, why the API is not taking care of that with limit=1 in leoric's example. I am sure there is a reason, I am not familiar with the internals of that process. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now