Skip to content

Commit

Permalink
fix(minimap): Refactor replay minimap rendering logic
Browse files Browse the repository at this point in the history
- Refactored the query to retrieve posts with associated replays and filter them based on the specified start and end dates.
- Added logging statements to track the progress of rendering all replay minimaps.
- Replaced the usage of `Replay` entity with `Post` entity in the loop for rendering each replay minimap.
- Updated log messages to reflect the changes made.

This commit fixes an issue with rendering replay minimaps and improves code readability.
  • Loading branch information
SakuraIsayeki committed Jul 23, 2023
1 parent 79da18c commit 620fb77
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions WowsKarma.Api/Services/MinimapRenderingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,21 @@ private async ValueTask UploadReplayMinimapAsync(Guid replayId, byte[] content,
[Tag("minimap", "replay", "render", "batch"), JobDisplayName("Render replay minimaps between {0} and {1}")]
public async Task ReprocessAllMinimapsAsync(DateTime? start, DateTime? end, bool force = false, CancellationToken ct = default)
{
_logger.LogWarning("Started reprocessing all replay minimaps between {start:g} and {end:g}", start, end);

var replays =
from replay in _context.Replays.Include(static r => r.Post)
where replay.Post.CreatedAt >= start && replay.Post.CreatedAt <= end
select replay;
_logger.LogWarning("Started rendering all replay minimaps between {start:g} and {end:g}", start, end);

IQueryable<Post> posts = _context.Posts.Include(static p => p.Replay)
.Where(p => p.Replay != null && p.CreatedAt >= start && p.CreatedAt <= end);

await foreach (Replay replay in replays.AsAsyncEnumerable().WithCancellation(ct))
int postsCount = await posts.CountAsync(ct);

_logger.LogWarning("Database readout complete. {count} replay minimaps will be rendered.", postsCount);

await foreach (Post post in posts.AsAsyncEnumerable().WithCancellation(ct))
{
_logger.LogDebug("Reprocessing replay minimap {replayId}", replay.Id);
await RenderPostReplayMinimapAsync(replay.Id, force, ct);
await RenderPostReplayMinimapAsync(post.Id, force, ct);
}

_logger.LogWarning("Replay Minimaps rendering complete! Rendered {count} replay minimaps total.", postsCount);
}

public async ValueTask<Uri> GenerateMinimapUriAsync(Guid replayId)
Expand Down

0 comments on commit 620fb77

Please sign in to comment.