-
Notifications
You must be signed in to change notification settings - Fork 10
#26: Implements a way to delete unwanted trashed nodes #29
base: develop
Are you sure you want to change the base?
Conversation
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. |
var minDate = DateTime.Now.AddDays(alwaysNegative); | ||
|
||
query = query.Where(x => x.UpdateDate < minDate); | ||
} |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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);
}
}
Sorry about removing the draft status - misclicked :) |
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! |
@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 :-) |
No worries, thank you for the work so far :) |
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, |
#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.