Views: 7483
Number of votes: 4
Average rating:

PageTypeBuilder and EPiServer CMS 6 R2 Synching Issues – Important


Background

There have been a couple of issues that have been logged on codeplex to do with long start up times and default values not being set on page definition properties, the links to the issues are below:

- After upgrading to PTB 2.0, starting site takes a really long time

- Default value is not set

Basically there was a change in CMS 6 R2 which changed how sort orders are handled.  When PageTypeBuilder is synching it will compare whether the page definition is different to the one stored in the database and if so it will update it.

In CMS 6 R2 a new method is now called named EnsureUniqueFieldOrder within the Save method of the PageDefinition.

At a high level this method does the following:

  1. Checks whether the sort order for the current page definition matches the sort order of any other page definitions for the page type and if it does it will set a new value for it.
  2. If a sort order has not been defined and there are existing page definitions it will get the highest sort order and add 1 to it.

This then has a potentially huge knock on effect because the next time the application starts PageTypeBuilder will go off and work it’s magic, but because the EnsureUniqueFieldOrder method has changed some of the sort orders, PageTypeBuilder will determine that the page definitions are different and update the definitions again Sad smile.

So to put simply this is not a bug in PageTypeBuilder or EPiServer it’s just a unfortunate side effect of not defining your Sort Order's in your page types or specifying duplicates.  Over time we often have many common base classes that page types will inherit from and can often be a case for many duplicates.

Introducing PageTypeBuilder.SortOrderChecker

Some of you may be aware that I spend a lot of time commuting to and from London town and that I like to fill this time with knocking together useful modules and applications.

So last week to fill this time I decided to knock together a little console application which will scan a bin folder and tell you which page types have duplicate and undefined properties.

It can also fix all of the page type files for you (assuming you are programming in C#) and apply new sort orders for various property definitions including property groups.  The fixing code will also fix sorting on page type and property group base classes too to ensure there are no duplicates.

Using PageTypeBuilder.SortOrderChecker

Firstly you will need to Download the executable and it’s config file from here and dump it in a folder on your machine. Then you need to follow the steps below:

1. Re-build your application to make sure all of your assemblies are up to date.
2. Backup any relevant EPiServer databases and source files Confused smile

3. Then you can execute the tool with the following arguments to determine which properties have duplicate or undefined sort orders.

c:\Tools\PageTypeBuilder.SortOrderChecker.exe -t:0 -b:c:\episerver\sites\pagetypebuildertest\bin

You will be shown a window like the following:


4. You can then attempt to fix your page types by running the following command, please note you may need to close visual studio first just in case there are any file locks.

c:\Tools\PageTypeBuilder.SortOrderChecker.exe -t:2 -b:c:\episerver\sites\pagetypebuildertest\bin -p:c:\episerver\sites\pagetypebuildertest

You will be shown a window like the following:


5. Now that your files have been fixed, you will need to rebuild the solution.  It may be possible that some classes/properties will not be updated, but this would probably be because of bad coding style, not by me of course Winking smile

Now we have rebuilt we can run the tool again to check for duplicates and unassigned sort orders.

c:\Tools\PageTypeBuilder.SortOrderChecker.exe -t:0 -b:c:\episerver\sites\pagetypebuildertest\bin

This time you will hopefully be told that all duplicates and unassigned sort orders are no more Thumbs up.



6.
One thing to be aware of is that as EPiServer has done it’s own thing for duplicate and undefined sort orders, it may still be likely that are some duplicates even though there are none in code.

To get round this you can run the tool again with the following commands.

c:\Tools\PageTypeBuilder.SortOrderChecker.exe -t:3 -b:c:\episerver\sites\pagetypebuildertest\bin -o:c:\temp\ResetSortOrders.sql 

This will create a .sql file with the necessary SQL to reset all PageTypeBuilder Property Definition sort orders to 0, so you will need to execute the SQL against your database.

7. Now that sort orders have been reset you can run your application. 

If you have a large number of page types and page definitions this initial update may take a bit longer than expected, but once this initial update is complete all future deployments/application restarts should be much quicker Smile.

Checking Sort Orders on post build event

You can hook the sort order checking executable into your application build by calling it on a post build event, it's not particularly elegant but will fail the build if there are duplicate or undefined sort orders and will output duplications and undefined properties on page types to the output window.

Command for post build:

c:\Tools\PageTypeBuilder.SortOrderChecker.exe -t:1 -b:$(TargetDir)




Disclaimer

Although I have done testing around this there could be possible side effects.  I take no responsibility for any adverse affects.  So basically use at your own risk and backup your database and source code first.

Feedback

Please feel free to email or twitter me with any feedback @croweman

Apr 23, 2012

tompipe
(By tompipe, 4/23/2012 2:25:36 PM)

Nice, very nice.

lee.crowe
(By lee.crowe, 4/23/2012 2:46:07 PM)

If anyone is brave enough it would be interesting to find the maximum number of duplicate/undefined sort orders and hear about the performance increase differences :)

Lars Bodahl
(By Lars Bodahl, 4/23/2012 6:13:56 PM)

Nice :) Our project implemented a similar, but more basic console app two weeks ago. Lots of pagetypes and several properties with duplicate sortorder. We reduced startuptime from 18 minutes to 2 minutes :-D

Filips Gajevskis
(By Filips Gajevskis, 4/23/2012 9:38:28 PM)

Great tool! Reduced start up time at about 30%.

P.S. Also mentioned a little bug, that if pagetype property is empty like PageType (), it adds SortOrder with comma like PageType (SortOrder = 32, ), that leads to an error when compiling.

Thanks)

lee.crowe
(By lee.crowe, 4/24/2012 12:21:04 PM)

Cool, I did consider the empty PageType attribute but I didn't think anyone would actually do that ;)

James Hurst
(By James Hurst, 4/25/2012 12:54:12 PM)

Great one. Managed to knock off about 40% off the start up time.
Now just got to get the other devs not to go and mess up my lovely ordering.....

lee.crowe
(By lee.crowe, 4/25/2012 1:01:50 PM)

Hi James

If you add the post build event mentioned in the article to the build the over dev's will not be able to break it :)

Lee

lee.crowe
(By lee.crowe, 4/27/2012 1:17:44 PM)

To verify that there are no more duplicates in the database you can you the following query, it should return no results. The where condition ignores undefined sort orders.

SELECT [fkPageTypeID], [FieldOrder]
FROM [tblPageDefinition]
WHERE [FieldOrder] > 0
GROUP BY [fkPagetypeID], [FieldOrder]
HAVING COUNT([FieldOrder]) > 1

Anders Murel
(By Anders Murel, 5/6/2012 11:03:32 PM)

God bless you!!

tompipe
(By tompipe, 5/15/2012 7:21:58 PM)

Thanks for re-tweeting this today Lee, I'd totally forgotten about it, and have been suffering with slow startups on the project I'm working on this week.

I'd used the PTB classes to discover properties which were using the default sort order, or were out of sync with the DB. There were loads, so I opted not to manually update them all at that point......thankfully.

I've just run your console app, and there were:

131 properties have duplicate sort orders
1408 properties have undefined sort orders
1539 properties have duplicate or undefined sort orders
page load took 144.109 seconds.

Running the fix reduced page load to 29.544 seconds and saved me from manually updating all the code!

I owe you a beer :)

manoj.dube
(By manoj.dube, 8/14/2013 3:32:16 PM)

Thanks a lot croweman this helped me...

Cheers :-)

Please login to comment.