From 0f6920003f64c9f1382f3740290803024838d472 Mon Sep 17 00:00:00 2001 From: ImoutoChan Date: Fri, 24 Nov 2023 23:09:03 +0400 Subject: [PATCH] Improve page prediction for yandere history loading --- .../Loaders/YandereLoaderTests.cs | 14 ++++++++++++++ .../BooruApiLoaderTagHistoryExtensions.cs | 9 ++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Imouto.BooruParser.Tests/Loaders/YandereLoaderTests.cs b/Imouto.BooruParser.Tests/Loaders/YandereLoaderTests.cs index fdd5b54..2a6ab07 100644 --- a/Imouto.BooruParser.Tests/Loaders/YandereLoaderTests.cs +++ b/Imouto.BooruParser.Tests/Loaders/YandereLoaderTests.cs @@ -221,6 +221,20 @@ public async Task ShouldGetTagHistoryFromIdToPresent() result.Should().NotBeEmpty(); result.DistinctBy(x => x.HistoryId).Should().HaveCount(result.Count); } + + /// + /// Bug with loading history after 4952686 + /// + [Fact] + public async Task ShouldGetTagHistoryFrom4952686IdToPresent() + { + var loader = _loaderFixture.GetLoader(); + + var result = await loader.GetTagHistoryFromIdToPresentAsync(4952686).ToListAsync(); + + result.Should().NotBeEmpty(); + result.DistinctBy(x => x.HistoryId).Should().HaveCount(result.Count); + } } public class GetPopularPostsAsyncMethod : YandereLoaderTests diff --git a/Imouto.BooruParser/Implementations/BooruApiLoaderTagHistoryExtensions.cs b/Imouto.BooruParser/Implementations/BooruApiLoaderTagHistoryExtensions.cs index b535612..d2efbca 100644 --- a/Imouto.BooruParser/Implementations/BooruApiLoaderTagHistoryExtensions.cs +++ b/Imouto.BooruParser/Implementations/BooruApiLoaderTagHistoryExtensions.cs @@ -44,7 +44,14 @@ public static async IAsyncEnumerable GetTagHistoryFromIdToPrese var predictedPage = (currentId - afterHistoryId) / 20 + 2; // validation - var page = await loader.GetTagHistoryPageAsync(new SearchToken($"{predictedPage}"), limit, ct); + HistorySearchResult page; + var tries = 10; + do + { + page = await loader.GetTagHistoryPageAsync(new SearchToken($"{predictedPage++}"), limit, ct); + tries--; + } while (!page.Results.Any() && tries > 0); + if (page.Results.All(x => x.HistoryId > afterHistoryId)) throw new Exception("Prediction failed");