Sitecore Development / Kim Hornung

Friday, March 23, 2007

A note on multiple save events per save operation

Recently I was fiddling around with the "item:save" event in Sitecore. And I noticed that in some situations, multiple save events are raised for a single save operation.

At that time, I simply figured that Sitecore’s UI might update different parts of the item in different operations (that does not make too much sense, but I was satisfied and yet again able to sleep at night).

But this week, I learned that this is implemented "by design".

What really happens is that Sitecore raises a save event for each version in all languages if you make any changes to a "shared" field (a field that only has one value for all versions in all languages). And if you make changes to a "versioned" field (a field that has one value per language), a save event will be raised for each version in the current language.

2 Comments:

  • A common pattern is to create a static unique collection object such as a static hashtable in the class handling the save. When the handler executes, if the item is already in the collection, do nothing, otherwise add it to the collection, execute the logic and remove it from the collection.

    By Blogger John, At 14:30  

  • Hi John,

    Thank you for the tip. But I fail to see how this allows me to only perform the desired action once per save action (although in most cases I would be able to hook into the SaveUI pipeline, if I just want to catch save actions performed by a user).

    /Kim

    By Blogger Kim, At 20:23  

Post a Comment

Subscribe to Post Comments [Atom]



<< Home