21

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.

10
  • 1
    is it one node + all of its descendants? List of IDs in multiple places in the tree?
    – Marek Musielak
    Commented Nov 3, 2016 at 14:00
  • Are you running the command in a bulk update context?
    – Richard Seal
    Commented Nov 3, 2016 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 Commented Nov 3, 2016 at 14:08
  • We are deleting one node and all descendants Marek. Commented Nov 3, 2016 at 14:09
  • How do you run in bulk update context Richard? Commented Nov 3, 2016 at 14:14

8 Answers 8

33

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.

7
  • 1
    Is this what you are referring to Marek: sitecoreunleashed.blogspot.com/2014/06/… or something similar? Commented Nov 3, 2016 at 14:23
  • @TobyGutierrez yes, exactly! I didn't know anyone else used same method :)
    – Marek Musielak
    Commented Nov 3, 2016 at 14:24
  • Thank Marek! Just wanted to make sure we were on the right track. Commented Nov 3, 2016 at 14:30
  • 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
    Commented Nov 3, 2016 at 15:43
  • 1
    @HarshBaid it took about 10 - 30 minutes to revert a tree with 1500 - 5000 items. This also depended on the hardware in the machine as well but significantly less and highly recommended! Commented Dec 1, 2016 at 22:12
25

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.

10

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."

1
  • This worked awesome for me. 16k items deleted in about 2 minutes. However, it deleted the parent item itself so I had to specify a subfolder of 2019 so it only deleted the children. I'm sure there's a way to tell it not to delete the item, only its children.
    – tjans
    Commented Oct 28, 2019 at 15:16
9

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.

1
  • 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. Commented Nov 3, 2016 at 14:18
3

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;
  }
}
2
  • Can you provide an example of how to do this so it doesn't become a link only answer please?
    – Richard Seal
    Commented Nov 3, 2016 at 14:51
  • This is old, but still largely valid, except that indexing is now disabled/enabled using the IndexCustodian::PauseIndexing() and IndexCustodian::ResumeIndexing() methods. Commented Feb 2, 2020 at 1:17
0

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.

0

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.

0

We can Use Sitecore Search interface in content editor to delete bulk children items,

  1. Apply * in search box to result all the child items enter image description here
  2. Apply Delete results operation through search operations available inbuilt

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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