Skip to content

Commit

Permalink
Merge pull request #131 from Gamhub-io/enhancement/#102_chunk_load
Browse files Browse the repository at this point in the history
Fixes - post chunk load implementation
  • Loading branch information
bricefriha authored Jun 15, 2024
2 parents 582f770 + bd23c99 commit f50b0d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions AresNews/AresNews/Services/Fetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ public async Task<Collection<Article>> GetFeedChunk(DateTime dateFrom, int lengt
{
try
{

//dateFrom = new DateTime(dateFrom.Year, dateFrom.Month, dateFrom.Day, dateFrom.Hour, dateFrom.Minute, 0);
string[] parameters = new string[]
{
dateFrom.AddHours(-length).ToString("dd-MM-yyy_HH:mm:ss"),
dateFrom.ToString("dd-MM-yyy_HH:mm:ss"),
dateFrom.AddMinutes(-1).ToString("dd-MM-yyy_HH:mm:ss"),
};
return await App.WService.Get<Collection<Article>>(controller: "feeds",
parameters: parameters,
Expand Down
13 changes: 9 additions & 4 deletions AresNews/AresNews/ViewModels/NewsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace AresNews.ViewModels
public class NewsViewModel : BaseViewModel
{
// Hour interval
private const int _refreshInterval = 12;
private const int _refreshInterval = 24;
private bool _isLaunching = true;
private string _prevSearch;
private string _lastCallDateTime;
Expand Down Expand Up @@ -517,17 +517,22 @@ public async Task FetchExistingArticles()
// Refresh the db
await RefreshDB().ConfigureAwait(false);
}
// Load the next chunk of articles
/// <summary>
/// Load the next chunk of articles
/// </summary>
/// <returns></returns>
private async Task LoadChunks()
{
if (_articles.Count <= 0)

if (_articles.Count <= 0 || IsLoadingChunks)
return;

IsLoadingChunks = true;
await Task.Run(async () =>
{
// get articles of the next 24hours after that
var collection = (await CurrentApp.DataFetcher.GetFeedChunk(_articles.LastOrDefault().FullPublishDate, 1)).Where(article => article.Blocked == null || article.Blocked == false).ToList();
var collection = (await CurrentApp.DataFetcher.GetFeedChunk(_articles.LastOrDefault().FullPublishDate, 12)).Where(article => article.Blocked == null || article.Blocked == false).ToList();
Articles.AddRange(collection);
}).ContinueWith(res => IsLoadingChunks = false);
Expand Down

0 comments on commit f50b0d3

Please sign in to comment.