Jump to content

Cloning is Slow


thetuningspoon
 Share

Recommended Posts

In an app I'm building I frequently need to clone a set of pages that represent a user's 'order'. Every time they make changes to the order, I want to make a new version by cloning this page structure. The pages in the structure also contain repeaters, so while there is in theory no limit to the number of pages in the structure, there would realistically be no more than about 30 pages (repeaters included).

From a coding perspective the clone() method makes this all a breeze. Unfortunately the clone operation just takes too long (~20 seconds). Does any one have any insight into why this is so slow? Is there any way around this aside from reducing the number of pages? Is there hope that we might be able to make this more efficient in a future version of PW?

Link to comment
Share on other sites

30 pages * x fields is a whole lot of insert statements to do on every change to an order, but 20 secs sounds indeed like somethings off. That's nearly a second per page to clone. Is that the time it takes locally or in production though?

  • Like 1
Link to comment
Share on other sites

Try to increase memory_limit and/or upgrade to PHP 7.2.

Are there a lot of files/images inside those pages/repeaters?

Perhaps try a clone() action in Tracy Debugger, maybe you'll see some hints what's slowing it down.

  • Like 1
Link to comment
Share on other sites

@thetuningspoon, it would be helpful if you could provide a limited test case (i.e. a minimal setup where this performance problem occurs), or if that's not possible/feasible, a description of the structure and this particular feature in as much detail as possible. For an example:

  • What's the page structure like, and which part of it is cloned?
  • Are users actual users or do you have "user" pages in a custom page structure – and if, do each of these have multiple orders? Or are you linking users to orders via a Page field or something along those lines?
  • How many fields do your orders (if order pages is what you are cloning) have?
  • How many Repeater fields there are, and approximately how many Repeater items (real content or ready items) do they contain?
  • How many users/orders are you dealing with?
  • Where in your page structure are you storing cloned orders?
  • Are there any third party modules (or modules/hooks you've created) that could affect this?

As you can see, this raises quite a few questions, and that's just the tip of the iceberg I'm afraid. All in all this sounds like something that would be easiest to debug by setting up a test case – otherwise it's difficult to isolate the issue.

As @LostKobrakai already pointed out, 20 seconds for cloning a relatively small page structure is not normal, unless there's a massive amount of data to copy (in db or on disk). If you're dealing with a large number of items, Repeaters could of course also play a role in this: after all each repeater item is a Page, and their storage method can also result in bottlenecks at large enough scale ?

  • Like 3
Link to comment
Share on other sites

@LostKobrakai This is on a production server.

@dragan There are no files or images.

@teppo We are creating a box subscription service where the user can have multiple boxes and configure what is included in each of them. The page structure is:

 

- Subscription (Not an actual user page, just linked to the user by a page field)
- - Boxset v1  <-- This is the page I'm calling clone on, and the resulting clone is stored as a sibling
- - - Box 1
- - - Box 2
- - - Box 3
- - - Box 4
- - Boxset v2
- - - Box 1
- - - Box 2
- - - Box 3
... etc

 

There are not many fields on each page (~3-4). But each Box has a repeater field on it which usually contains 6 entries. The repeater is using AJAX to generate new items. The 30 pages number I came up with included the repeater pages.

I've switched to using a ProFields Table field instead of a repeater since I think it will actually serve us just as well in this case. The clone time is now greatly reduced, although still feels a bit slow to me.

It does sound like I should set up a test case and some debugging to see if something weird is going on. Thanks everyone for your feedback and let me know if you have any further thoughts!

  • Like 1
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...