We are trying to delete tens of thousands of items in the content tree. However, it is taking a VERY long time to do that. We have tried to delete through the Sitecore Experience Editor and it is timing out. We love Sitecore Powershell Extensions (SPE), and have tried to use the Remove-Item cmdlet and that works but still takes a VERY long time...even overnight.

What is the fastest way to delete tens of thousands of items from the Sitecore content tree? Your help is much appreciated.

  • 1
    is it one node + all of its descendants? List of IDs in multiple places in the tree? – Marek Musielak Nov 3 '16 at 14:00
  • Are you running the command in a bulk update context? – Richard Seal Nov 3 '16 at 14:05
  • I would have ran a SQL Script. I will search in my files if I have something like this. Most of the time, if I have to perform bulk insert or modification, I do it via sql which takes few minutes – Hishaam Namooya Nov 3 '16 at 14:08
  • We are deleting one node and all descendants Marek. – Toby Gutierrez Nov 3 '16 at 14:09
  • How do you run in bulk update context Richard? – Toby Gutierrez Nov 3 '16 at 14:14
up vote 19 down vote accepted

When I was working on Sitecore 7.2 project long time ago, the fastest way was to serialize the single root item and then clicking Revert Tree on that item. All the descendants were gone and I had to remove only the last item manually.

It worked in EventDisabler mode and it was much much faster than deleting items manually.

  • Is this what you are referring to Marek: sitecoreunleashed.blogspot.com/2014/06/… or something similar? – Toby Gutierrez Nov 3 '16 at 14:23
  • @TobyGutierrez yes, exactly! I didn't know anyone else used same method :) – Marek Musielak Nov 3 '16 at 14:24
  • Thank Marek! Just wanted to make sure we were on the right track. – Toby Gutierrez Nov 3 '16 at 14:30
  • What happens to child items in the database in this case? Are they actually deleted from the SQL tables or just left stray? – jammykam Nov 3 '16 at 15:27
  • 1
    @jammykam yes they are deleted. It runs in EventDisabler scope and raises SerializationFinishedEvent after it's done. From what I checked, the only subscriber for that event is method which clears all the caches. So all the other things like updating links database or index updates are not executed. – Marek Musielak Nov 3 '16 at 15:43

This is another option you have if you want to use Sitecore PowerShell Extensions. Delete the items in a BulkUpdateContext - this disables events etc... an so makes the delete run a lot faster. To do that in SPE you can use this syntax:

New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
    Get-Item -Path master:/sitecore/Content/myItem | Remove-Item
}

Because this does disable events etc... you will probably need to re-index and run a smart publish once the items are deleted.

If you are not worried about missing reference for these deleted items, the faster way to do it is by using /sitecore/admin/dbbrowser.aspx tool.

It skips lot of pipeline processors which makes it much faster than deleting from content editor.

  • The problem with this for us on this project is that we can't even get to it to delete this many items, which is over 80K at this point. But I do agree, this is a great option for fast deletion of items less than this many. – Toby Gutierrez Nov 3 '16 at 14:18

If your items are spread around the tree, write some code to do it and wrap it in all disablers you can. This blog has some nice info about it.

The SecurityDisabler will help the process a lot as no security is checked anymore. Disabling all events and index updates will also free a lot of resources for the actual delete.

You will need to clear the Sitecore caches and rebuild any indexes that refer to the items that you were updating afterwards as no events or index updates will be done.

Example:

using (new SecurityDisabler())
using (new DatabaseCacheDisabler())
using (new EventDisabler())
using (new BulkUpdateContext())
{
  try
  {
    Sitecore.Configuration.Settings.Indexing.Enabled = false;

    // delete items here
  }
  finally
  {
    Sitecore.Configuration.Settings.Indexing.Enabled = true;
  }
}
  • Can you provide an example of how to do this so it doesn't become a link only answer please? – Richard Seal Nov 3 '16 at 14:51

Another way to increase the speed of removing items is to skip the recycling bin. Here is an example in combination with using bulk update.

New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
  Get-Item "master:/content/Something" | Remove-Item -Recurse -Permanently
}

Here is the documentation on deleting items permanently: https://doc.sitecorepowershell.com/working-with-items.html

Relevant information: "Permanently - Specifies the item should be deleted rather than recycled."

Not tested, but we can try with taking a package of parent item/node alone(one single item), and installing the same package with Overwrite option when asked for.

I was recently in the situation to delete lots of item from different places from a Sitecore solution v8.1u3 and I have used Sitecore Rock. I've used it in 2 ways:

  1. Directly in the content tree of the Sitecore Rocks, just make a delete on the contextual menu when you right click on the items.
  2. Or use Sitecore Query inside Sitecore Rocks. Example of delete queries.

Option #1 is slow, but option #2 was quite satisfactory for me. But I was in my development environment.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.