Jump to content

create new page very slow


leoric
 Share

Recommended Posts

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

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

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

$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.

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...