mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
Added cleanup job for search history
New: Search History cleanup job will only keep the last week of results
This commit is contained in:
parent
c50ed82b7e
commit
b7408b726a
5 changed files with 159 additions and 0 deletions
|
@ -66,6 +66,46 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||
i.SearchError = ReportRejectionType.None;
|
||||
}
|
||||
|
||||
private void WithExpiredHistory()
|
||||
{
|
||||
var history = Builder<SearchHistory>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(h => h.SearchTime = DateTime.Now.AddDays(10))
|
||||
.Build();
|
||||
|
||||
foreach(var searchHistory in history)
|
||||
{
|
||||
var items = Builder<SearchHistoryItem>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(i => i.Id == searchHistory.Id)
|
||||
.Build();
|
||||
|
||||
Db.InsertMany(items);
|
||||
}
|
||||
|
||||
Db.InsertMany(history);
|
||||
}
|
||||
|
||||
private void WithValidHistory()
|
||||
{
|
||||
var history = Builder<SearchHistory>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(h => h.SearchTime = DateTime.Now)
|
||||
.Build();
|
||||
|
||||
foreach (var searchHistory in history)
|
||||
{
|
||||
var items = Builder<SearchHistoryItem>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(i => i.Id == searchHistory.Id)
|
||||
.Build();
|
||||
|
||||
Db.InsertMany(items);
|
||||
}
|
||||
|
||||
Db.InsertMany(history);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Add_should_add_history_and_history_items()
|
||||
{
|
||||
|
@ -263,5 +303,54 @@ namespace NzbDrone.Core.Test.ProviderTests
|
|||
|
||||
Mocker.GetMock<DownloadProvider>().Verify(v => v.DownloadReport(It.IsAny<EpisodeParseResult>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Cleanup_should_not_blowup_if_there_is_nothing_to_delete()
|
||||
{
|
||||
WithRealDb();
|
||||
|
||||
Mocker.Resolve<SearchHistoryProvider>().Cleanup();
|
||||
Db.Fetch<SearchHistory>().Should().HaveCount(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Cleanup_should_delete_searchHistory_older_than_1_week()
|
||||
{
|
||||
WithRealDb();
|
||||
WithExpiredHistory();
|
||||
|
||||
Mocker.Resolve<SearchHistoryProvider>().Cleanup();
|
||||
Db.Fetch<SearchHistory>().Should().HaveCount(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Cleanup_should_delete_searchHistoryItems_older_than_1_week()
|
||||
{
|
||||
WithRealDb();
|
||||
WithExpiredHistory();
|
||||
|
||||
Mocker.Resolve<SearchHistoryProvider>().Cleanup();
|
||||
Db.Fetch<SearchHistoryItem>().Should().HaveCount(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Cleanup_should_not_delete_searchHistory_younger_than_1_week()
|
||||
{
|
||||
WithRealDb();
|
||||
WithValidHistory();
|
||||
|
||||
Mocker.Resolve<SearchHistoryProvider>().Cleanup();
|
||||
Db.Fetch<SearchHistory>().Should().HaveCount(10);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Cleanup_should_not_delete_searchHistoryItems_younger_than_1_week()
|
||||
{
|
||||
WithRealDb();
|
||||
WithValidHistory();
|
||||
|
||||
Mocker.Resolve<SearchHistoryProvider>().Cleanup();
|
||||
Db.Fetch<SearchHistoryItem>().Should().HaveCount(100);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue