lpa Posted December 23, 2021 Share Posted December 23, 2021 I am having slow performance when moving pages to a new location using api. What could be the reason that moving one page takes 3-4 seconds with this code? I think it should move many pages per second. Could it be the page path history, that takes so long to save? $to = $pages->get('/path/to/'); $articles = $pages->get('/path/from/')->children(); $i = 0; $c = $articles->count(); foreach ( $articles as $item ) { $item->of(false); $item->original_category = $item->parent->title; $item->original_path = $item->url; $item->parent = $to; $item->save(); $i++; printf("%d/%d %s \r", $i, $c, $item->url); } Link to comment Share on other sites More sharing options...
Zeka Posted December 23, 2021 Share Posted December 23, 2021 Hi @lpa It depends on how many pages you have in the system. There is a 'rebuildAll' method in the PagesParents class that runs every time you move a page. Take a look at this issue https://github.com/processwire/processwire-issues/issues/1459 You can try to use transactions if you use InnoDB. Link to comment Share on other sites More sharing options...
lpa Posted December 23, 2021 Author Share Posted December 23, 2021 OK, thanks. And there seems to be no solution yet for this problem. Or how could I use transactions? Link to comment Share on other sites More sharing options...
Jan Romero Posted December 23, 2021 Share Posted December 23, 2021 While I agree that it shouldn’t be slow, I feel like moving pages should be an extremely rare occurrence and if you do it frequently as part of your usual operations, there probably exists a better way. Especially if those pages are publically accessible, because cool urls don’t change. For pages that just hold internal data, maybe one of the Repeater variants could be a better fit. Or a ProFields Table, or a something custom. Maybe instead of moving children around, just have Page References. Link to comment Share on other sites More sharing options...
lpa Posted December 23, 2021 Author Share Posted December 23, 2021 Yes I agree. But we are doing a big restructuring of our content and to have the redirections handled by PW page history, we are moving the pages using the API. Unfortunately we have thousands of pages to move to archive and it will take time.... 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