Skip to content

Commit bb68b29

Browse files
committed
fix: return post ids from controller
1 parent 4c2724b commit bb68b29

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

ApplicationData/Services/RedditPostProvider.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ UPDATE reddit_posts
6060
""", new { redditPostId, title }, cancellationToken);
6161
}
6262

63-
public async Task<int> CountPostsNeedingTitleFetched(CancellationToken cancellationToken)
63+
public async IAsyncEnumerable<string> GetPostsNeedingTitleFetched([EnumeratorCancellation] CancellationToken cancellationToken)
6464
{
6565
await using var connection = _dbConnectionFactory.CreateReadOnlyConnection();
66-
return await connection.ExecuteScalar<int>(
67-
"SELECT COUNT(*) FROM reddit_posts WHERE is_title_fetched = 0",
66+
67+
var query = connection.QueryUnbuffered<string>("SELECT reddit_post_id FROM reddit_posts WHERE is_title_fetched = 0",
6868
cancellationToken: cancellationToken);
69+
70+
await foreach (var redditPostId in query)
71+
yield return redditPostId;
6972
}
7073
}

WebApi/Controllers/Admin/AdminQueueController.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,8 @@ public async Task<IActionResult> GetProcessingQueue(CancellationToken cancellati
5555
/// </summary>
5656
[HttpGet]
5757
[Route("post-title-backlog")]
58-
public async Task<IActionResult> GetPostTitleFetchBacklog(CancellationToken cancellationToken)
58+
public IAsyncEnumerable<string> GetPostTitleFetchBacklog(CancellationToken cancellationToken)
5959
{
60-
var count = await _redditPostProvider.CountPostsNeedingTitleFetched(cancellationToken);
61-
62-
return new OkObjectResult(new
63-
{
64-
postsNeedingTitleFetchedCount = count,
65-
});
60+
return _redditPostProvider.GetPostsNeedingTitleFetched(cancellationToken);
6661
}
6762
}

0 commit comments

Comments
 (0)