Cleanup content version

Content versions are not cleaned up with the following app settings

app settings:

“Content”: { “ContentVersionCleanupPolicy”: { “EnableCleanup”: true, “KeepLatestVersionPerDayForDays”: 5, “KeepAllVersionsNewerThanDays”: 2 },

Prevent cleanup is NOT enabled for any document types.

The content history is maintained since Oct 2024 till today Jun 2026.

Why is the content version is not cleaned up.

Umbraco version 13.5.2.

We’ve had an issue that if the backlog for the cleanup would get too long, the job would timeout and not clean up correctly. This would obviously only get worse once the backlog got longer and longer. There is a fix in v17 to make it faster, but I don’t think that’s ported back to v13.

You should really update to the latest v13. Maybe there are some fixes that help you, but also a number of security fixes that are really important.

I’ve had similar issue in earlier versions of Umbraco 16 and 17, where the backlog got too large as @Luuk mentions.

I “fixed” it by running some code, tricking the cleanup service into thinking we are in the past :slight_smile:

    [Route("/api/contentversioncleanup")]
    public class ContentVersionCleanupController(IContentVersionService service) : Controller
    {
        [HttpGet]
        [Route("{days}")]
        public async Task<IActionResult> Get([FromRoute] int days)
        {
            return Ok(service.PerformContentVersionCleanup(DateTime.UtcNow.AddDays(days)).Count);
        }
    }

So with this controller, I just started running it with eg. days=-100, days=-75 and so forth, until I got through everything.

There is also a MaxVersionsToDeletePerRun (default 50k) if it is a timeout issue..

Content Settings | CMS | Umbraco Documentation

but missing in the docs for config here :frowning:

Umbraco-CMS/src/Umbraco.Core/Services/ContentVersionServiceBase.cs at main · umbraco/Umbraco-CMS

        DateTime olderThan = asAtDate.AddDays(-effectiveKeepAllDays);
        int? fetchLimit = versionCleanupPolicy.MaxVersionsToDeletePerRun > 0
            ? versionCleanupPolicy.MaxVersionsToDeletePerRun
            : null;
    /// <summary>
    ///     Gets or sets the maximum number of content versions to process per cleanup run.
    ///     When more versions are eligible, they will be processed in subsequent runs.
    ///     A value of 0 means no limit (process all eligible versions).
    /// </summary>
    [DefaultValue(StaticMaxVersionsToDeletePerRun)]
    public int MaxVersionsToDeletePerRun { get; set; } = StaticMaxVersionsToDeletePerRun;

Umbraco-CMS/src/Umbraco.Core/Configuration/Models/ContentVersionCleanupPolicySettings.cs at main · umbraco/Umbraco-CMS

Unfortunately that setting was added in the fix for v17, so it’s not available in 13.

You could augment and replace the contentversioningService in v13 to you own spec.. (Hopefully not too many private/internal methods to deal with?)

using Umbraco-CMS/src/Umbraco.Core/Services/ContentVersionService.cs at 5360e2a9681ce2d0024be374e80339260bcc2511 · umbraco/Umbraco-CMS · GitHub, as your starting point?

Augment the filter to reduce the count of items?

or further downstream, augment and replace the defaultcontentversioningpolicy?

Services.AddUnique<IContentVersionCleanupPolicy, MyCustomContentVersionCleanupPolicy>();