Jump to content

Website has become extremely slow


tires
 Share

Recommended Posts

Thank you very much for your advice!

I have indeed found a hook that was apparently to blame. I can't remember exactly why I added it and what it does ...

$wire->addHookAfter('Pages::saveReady', function($event) {
  $event->modules->get('SearchEngine')->indexPages();
  $page = $event->arguments(0);
  $event->wire('log')->save('Page saved', "Page ID: $page->id / Page Name: $page->name / Page Parents: $page->parents");
});

 

  • Like 3
Link to comment
Share on other sites

  On 12/18/2024 at 3:23 PM, da² said:

Solution is here: https://processwire.com/modules/search-engine/

// Alternatively index just a single page (passing in a Page object):
$modules->get('SearchEngine')->indexPage($page);

 

Expand  

I can't really remember why I used this module (it's been a few years).
Do I really need it to find the content of the pages?

You mean I should simply adapt the ready.php to, right?

$wire->addHookAfter('Pages::saveReady', function($event) {
  $event->modules->get('SearchEngine')->indexPages($page);
  $page = $event->arguments(0);
  $event->wire('log')->save('Page saved', "Page ID: $page->id / Page Name: $page->name / Page Parents: $page->parents");
});

Thank a lot!

Link to comment
Share on other sites

  On 12/19/2024 at 7:13 PM, tires said:

Do I really need it to find the content of the pages?

Expand  

If you have a search page that allows to search text in a lot of pages containing big texts, you probably need it. Do a performance benchmark with and without.

  On 12/19/2024 at 7:13 PM, tires said:

You mean I should simply adapt the ready.php to, right?

Expand  

Yes but without the mistake you did on the method name. 😁 

Edited by da²
  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
  On 1/7/2025 at 10:43 PM, tires said:

Really, i don't understand what you mean right now.

Expand  

In your hook posted above you use “indexPages()”, but the correct one would be “indexPage($page)” without the s at the end.

Your hook creates a completely new search index each time, not only for the changed page but for all pages.

You have to use something like this (not tested)

$wire->addHookAfter('Pages::saveReady', function($event) {
  $page = $event->arguments(0);
  $event->modules->get('SearchEngine')->indexPage($page);
  $event->wire('log')->save('Page saved', "Page ID: $page->id / Page Name: $page->name / Page Parents: $page->parents");
});

 

  • Like 2
Link to comment
Share on other sites

  On 12/21/2024 at 5:31 PM, tires said:

does the module automatically index the edited page when it is saved?

Expand  

Yes, it does.

As others have pointed out: if you only want to index a single page, indexPage($page) is the correct method — but I also have no idea what the purpose of that would be. My guess is that it was either added due to some kind of misunderstanding, or perhaps you indeed did want to recreate the full index every time a page is saved. If it was the latter reason then that might make some sense, but it is also a very bad idea in terms of performance (as you've noted here) 🙂

  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...
  On 1/8/2025 at 6:57 AM, zoeck said:

In your hook posted above you use “indexPages()”, but the correct one would be “indexPage($page)” without the s at the end.

Your hook creates a completely new search index each time, not only for the changed page but for all pages.

You have to use something like this (not tested)

$wire->addHookAfter('Pages::saveReady', function($event) {
  $page = $event->arguments(0);
  $event->modules->get('SearchEngine')->indexPage($page);
  $event->wire('log')->save('Page saved', "Page ID: $page->id / Page Name: $page->name / Page Parents: $page->parents");
});

 

Expand  

Thank you very much.
I have now simply removed this hook.

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