U4-10504 - Previewing content results in the same PrepareDocument (expensive) procedure to be executed 3 times

Created by Shannon Deminick 06 Oct 2017, 01:51:23 Updated by Eric Wilkinson 16 Mar 2018, 14:20:09

Tags: Backport

Relates to: U4-4778

Relates to: U4-5228

Relates to: U4-9072

Subtask of: U4-9609

Previewing a content item is an expensive operation that needs to updating but what makes this worse is that when you press the preview button, due to the sequence of events that ensues, the PreviewContext.PrepareDocument method is executed 3 times! This means that for one single preview, this very expensive method may iterate your entire content tree 3 times and make at least a few requests per content item.


Shannon Deminick 12 Oct 2017, 07:28:31

PR https://github.com/umbraco/Umbraco-CMS/pull/2237

Here's what's been done:

  • when we redirect to the /umbraco/preview page we also now pass in an 'init' parameter, the js controller for the preview page will see this and exit so that it doesn't load in the Preview.aspx page. The reason this used to double load Preview.aspx is because this /umbraco/preview is double loaded due to a trick we need to utilize to get around the chrome popup blocker. So on first load it just opens a window, on second load there is no 'init' parameter so it loads Preview.aspx
  • we no longer generate any preview stuff in the ContentController, this is always done in the preview.aspx page. I've had a look at the issue raised here (which is why we added this logic to the ContentController in the first place) http://issues.umbraco.org/issue/U4-3638 and the issue doesn't exist. To clarify, it's this issue: "But even so like you say, if Save and Publish is clicked the preview content should probably be updated too.". So you can test this - have a tab for back office open and a tab for the front-end open, then make changes to the page in the back office and press preview - a 3rd tab will open and it will show you the published content. Go back to your other front end tab and reload, this will also show you the preview content. Then go make another change to the document and press Save + Publish. Refresh the front-end tab page and you'll see the published content

To verify that we are now only generating ONE preview set, you can clear out the App_data/preview files, then go press preview on a content node, you'll notice only one file is created.

phew... this should save on a tremendous amount of overhead for previewing

Robert Copilau 17 Oct 2017, 08:19:53

Nice! I can confirm that only one preview set is being created, merged :).

Priority: Major

Type: Bug

State: Fixed


Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version: 7.7.4

Sprint: Sprint 70

Story Points: 1

Cycle: 5