Created
September 17, 2020 21:42
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
@sansani4 The cleanup database option in administration tools is what removes orphaned blobs from the blob table. :)
Database and Operations --> Database Cleanup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)