tires Posted December 18, 2024 Share Posted December 18, 2024 I have a site with about 5000 subpages and have noticed that it now takes about 10 seconds to save a page. What could be the reason for this and how can I speed up the site? Link to comment Share on other sites More sharing options...
AndZyk Posted December 18, 2024 Share Posted December 18, 2024 Hello @tires, have you tried looking in TracyDebugger if there is an error? Do you use hooks or special modules? The amount of subpages should not be an issue in my experience. Maybe there is something else going on. Regards, Andreas 1 Link to comment Share on other sites More sharing options...
tires Posted December 18, 2024 Author Share Posted December 18, 2024 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"); }); 3 Link to comment Share on other sites More sharing options...
da² Posted December 18, 2024 Share Posted December 18, 2024 2 hours ago, tires said: $event->modules->get('SearchEngine')->indexPages(); You are indexing all the site pages every time a page is saved. You should index only this page since the work for other ones was already done. 3 Link to comment Share on other sites More sharing options...
AndZyk Posted December 18, 2024 Share Posted December 18, 2024 Happy to hear you found the issue. 😀 You could consider indexing the pages with a Lazy Cron or a cronjob. 2 Link to comment Share on other sites More sharing options...
da² Posted December 18, 2024 Share Posted December 18, 2024 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); 3 Link to comment Share on other sites More sharing options...
tires Posted December 19, 2024 Author Share Posted December 19, 2024 On 12/18/2024 at 4: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); 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 More sharing options...
da² Posted December 20, 2024 Share Posted December 20, 2024 (edited) 6 hours ago, tires said: Do I really need it to find the content of the pages? 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. 6 hours ago, tires said: You mean I should simply adapt the ready.php to, right? Yes but without the mistake you did on the method name. 😁 Edited December 20, 2024 by da² 1 Link to comment Share on other sites More sharing options...
tires Posted December 21, 2024 Author Share Posted December 21, 2024 On 12/20/2024 at 3:02 AM, da² said: Yes but without the mistake you did on the method name. 😁 Which mistake do you mean? 🤓 By the way, do I need this hook at all or does the module automatically index the edited page when it is saved? Link to comment Share on other sites More sharing options...
da² Posted December 21, 2024 Share Posted December 21, 2024 1 minute ago, tires said: Which mistake do you mean? 🤓 I won't help for reading a function name. 😆 2 minutes ago, tires said: By the way, do I need this hook at all or does the module automatically index the edited page when it is saved? I don't know the module, check the documentation. Link to comment Share on other sites More sharing options...
tires Posted 20 hours ago Author Share Posted 20 hours ago On 12/21/2024 at 6:34 PM, da² said: I won't help for reading a function name. 😆 Please, come on! 😆 Really, i don't understand what you mean right now. Link to comment Share on other sites More sharing options...
zoeck Posted 11 hours ago Share Posted 11 hours ago 8 hours ago, tires said: Really, i don't understand what you mean right now. 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"); }); 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