Skip to content

Commit

Permalink
Improve page prediction for yandere history loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ImoutoChan committed Nov 24, 2023
1 parent f687514 commit 0f69200
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Imouto.BooruParser.Tests/Loaders/YandereLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@ public async Task ShouldGetTagHistoryFromIdToPresent()
result.Should().NotBeEmpty();
result.DistinctBy(x => x.HistoryId).Should().HaveCount(result.Count);
}

/// <summary>
/// Bug with loading history after 4952686
/// </summary>
[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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ public static async IAsyncEnumerable<TagHistoryEntry> GetTagHistoryFromIdToPrese
var predictedPage = (currentId - afterHistoryId) / 20 + 2;

// validation
var page = await loader.GetTagHistoryPageAsync(new SearchToken($"{predictedPage}"), limit, ct);
HistorySearchResult<TagHistoryEntry> 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");

Expand Down

0 comments on commit 0f69200

Please # to comment.