Jump to content

Moving a page under a new parent by API is very slow


Recommended Posts

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->original_category = $item->parent->title;
        $item->original_path = $item->url;
        $item->parent = $to;

        printf("%d/%d %s                                                   \r", $i, $c, $item->url);


Link to comment
Share on other sites

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

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

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

  • Recently Browsing   0 members

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