Skip to content

Instantly share code, notes, and snippets.

@danielrolfe
Created September 17, 2020 21:42
Show Gist options
  • Save danielrolfe/4c594513a0ce4c41af93c9980fa07faf to your computer and use it in GitHub Desktop.
Save danielrolfe/4c594513a0ce4c41af93c9980fa07faf to your computer and use it in GitHub Desktop.
Simple SQL script to delete the recycle bin rows from the Sitecore Archive tables. Use it at your own risk!
declare @CleanupList table(ArchivalId uniqueidentifier)
declare @ArchivalId uniqueidentifier
insert into @CleanupList(ArchivalId)
select ArchivalId
from dbo.Archive
where ArchiveName = 'recyclebin'
while(1 = 1)
begin
set @ArchivalId = NULL
select top (1) @ArchivalId = ArchivalId
from @CleanupList
if @ArchivalId IS NULL
break
delete from dbo.ArchivedFields where ArchivalId = @ArchivalId
delete from dbo.ArchivedItems where ArchivalId = @ArchivalId
delete from dbo.ArchivedVersions where ArchivalId = @ArchivalId
delete from dbo.Archive where ArchivalId = @ArchivalId
delete top(1) from @CleanupList
end
@danielrolfe
Copy link
Author

Thank you @ezlateva

@sansani4
Copy link

sansani4 commented Jul 19, 2023

I have a question. What about Blobs table? Whey looking at "Query Performance Insight" I see the following queries being very heavy:

Query 1:

(@archiveName nvarchar(10))DELETE FROM [Blobs] WHERE [BlobId] IN ( SELECT [Blobs].[BlobId] FROM [ArchivedFields], [Blobs] WHERE [ArchivalId] IN (SELECT [ArchivalId] FROM [Archive] WHERE [ArchiveName] = @archiveName AND [Value] LIKE [Blobs].[BlobId]))

Query 2

(@archivalId uniqueidentifier)DELETE FROM [Blobs] WHERE CONVERT(nvarchar(36), [BlobId]) IN (SELECT [Blobs].[BlobId] FROM [ArchivedFields], [Blobs] WHERE [ArchivalId] = @archivalId AND [Value] LIKE [Blobs].[BlobId])

(In my case, empty Recycle Bin button click caused timeout, and first query is the one bein mentioned).

I am just wondering - if I delete Archival entries, would not orphaned blobs still hang around and take space (for recycled image items I presume)

@danielrolfe
Copy link
Author

@sansani4 The cleanup database option in administration tools is what removes orphaned blobs from the blob table. :)

@danielrolfe
Copy link
Author

Database and Operations --> Database Cleanup

@sansani4
Copy link

Thank you so much!!! I see it!

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment