Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

#26: Implements a way to delete unwanted trashed nodes #29

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jannikanker
Copy link

#26

Something's off with file encodings/line endings, it seems :-( @skttl do you have some special settings or is my Visual Studio being extraordinarily dumb?

Also, I figured I'd wait with updating the docs until I know if this is even remotely usable. But I'll of course update docs if needed.

@skttl
Copy link
Owner

skttl commented Oct 28, 2020

Looking good!

I think the MaxCount setting in config should define how many trashed items you want to keep though, not how many you want to clean per run.

@skttl skttl marked this pull request as ready for review October 28, 2020 07:27
var minDate = DateTime.Now.AddDays(alwaysNegative);

query = query.Where(x => x.UpdateDate < minDate);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to handle MaxCount from config too, so if we take your config example, it should make sure that there is not more than 100 trashed newsPages trashed in the last 30 days.

}

// We'll not handle more than 100 nodes per cycle - if we don't handle it now, we'll get to it eventually
var nodesToDelete = _contentService.GetPagedContentInRecycleBin(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the config has a MaxCount, this one should skip the first x (x = MaxCount) nodes before deleting.

I think it can be something like

IEnumerable<IContent> nodesToDelete;
if (cfg.MaxCount > 0)
{
    var i = 1;
    while (true)
    {
        nodesToDelete = _contentService.GetPagedContentInRecycleBin(i, cfg.MaxCount, out long totalRecords);
        if (!nodesToDelete.Any())
        {
            break;
        }
        else
        {
            foreach (var node in nodesToDelete)
            {
                _logger.Debug<CleanUpTrashTask>("Deleting content {contentId} from Recycle Bin", content.Id);
                _contentService.Delete(content);
            }
            i++;
        }
    }
}
else
{
    // just delete everything - this will only be problematic on the first run and if the recycle bin is huge
    nodesToDelete = _contentService.GetPagedContentInRecycleBin(0, int.MaxValue, out long totalRecords);
    foreach (var node in nodesToDelete)
    {
        _logger.Debug<CleanUpTrashTask>("Deleting content {contentId} from Recycle Bin", content.Id);
        _contentService.Delete(content);
    }
}

@skttl
Copy link
Owner

skttl commented Oct 28, 2020

Sorry about removing the draft status - misclicked :)

@jannikanker
Copy link
Author

I think the MaxCount setting in config should define how many trashed items you want to keep though, not how many you want to clean per run.

Ah, yes, I guess that makes sense to "flip" that logic. So the MaxCount setting would mean "this is the maximum amount of this node type we want to keep in recycle bin". I'll fix that later today!

@jannikanker
Copy link
Author

@skttl FYI: I haven't forgotten about this one - life kinda got in the way but I'm hoping I'll be able to finish it off this week :-)

@skttl
Copy link
Owner

skttl commented Nov 10, 2020

No worries, thank you for the work so far :)

@umbrabot
Copy link

Hi there @jannikanker,

First of all: A big #H5YR for making an Umbraco related contribution during Hacktoberfest! We are very thankful for the huge amount of PRs submitted, and all the amazing work you've been doing 🥇

Due to the amazing work you and others in the community have been doing, we've had a bit of a hard time keeping up. 😅 While all of the PRs for Hacktoberfest might not have been merged yet, you still qualify for receiving some Umbraco swag, congratulations! 🎉

In the spirit of Hacktoberfest we've prepared some exclusive Umbraco swag for all our contributors - including you!

As a new choice this year, you can opt-out of receiving anything and ask us to improve the planet instead by planting a tree on your behalf. 🌳

Receive your swag or plant a tree! 👈 Please follow this link to fill out and submit the form, before February 26, 2021.

Following this date we'll be sending out all the swag, which also means that it might not reach your doorstep before April, so please bear with us and be patient 🙏

The only thing left to say is thank you so much for participating in Hacktoberfest! We really appreciate the help!

Kind regards,
The various Umbraco Teams

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants