Skip to content

Commit

Permalink
fix mal tracking service taking long time to load my list
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniachi committed Jun 9, 2024
1 parent 1f62ecd commit 16c712d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 31 deletions.
49 changes: 21 additions & 28 deletions Totoro.Core/Services/MyAnimeList/MyAnimeListTrackingService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System.Diagnostics;
using System.Globalization;
using MalApi.Interfaces;
using Microsoft.Extensions.Configuration;
using Splat;
Expand All @@ -10,14 +11,6 @@ public class MyAnimeListTrackingService : ITrackingService, IEnableLogger
{
private readonly IMalClient _client;
private readonly IAnilistService _anilistService;
private readonly MalApi.AnimeStatus[] _statuses =
[
MalApi.AnimeStatus.Watching,
MalApi.AnimeStatus.PlanToWatch,
MalApi.AnimeStatus.Completed,
MalApi.AnimeStatus.OnHold,
MalApi.AnimeStatus.Dropped
];
private static readonly string[] _fieldNames =
[
MalApi.AnimeFieldNames.Synopsis,
Expand Down Expand Up @@ -72,29 +65,29 @@ public async IAsyncEnumerable<AnimeModel> GetAnime()
yield break;
}

foreach (var status in _statuses)
{
var result = await _client.Anime()
.OfUser()
.WithStatus(status)
.IncludeNsfw()
.WithFields(_fieldNames)
.Find();
var result = await _client.Anime()
.OfUser()
.IncludeNsfw()
.WithFields(_fieldNames)
.Find();

foreach (var item in result.Data)
{
var model = ConvertModel(item);

foreach (var item in result.Data)
if (model.Tracking.Status == AnimeStatus.Watching && model.AiringStatus == AiringStatus.CurrentlyAiring)
{
var model = ConvertModel(item);

if (status == MalApi.AnimeStatus.Watching && model.AiringStatus == AiringStatus.CurrentlyAiring)
{
var epAndTime = await _anilistService.GetNextAiringEpisode(item.Id);
model.AiredEpisodes = epAndTime.Episode - 1 ?? 0;
model.NextEpisodeAt = epAndTime.Time;
}

yield return model;
Observable
.FromAsync(_ => _anilistService.GetNextAiringEpisode(item.Id), RxApp.TaskpoolScheduler)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x =>
{
model.AiredEpisodes = x.Episode - 1 ?? 0;
model.NextEpisodeAt = x.Time;
});
}

yield return model;
}
}

Expand Down
3 changes: 2 additions & 1 deletion Totoro.Core/Services/TrackingServiceContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reactive.Subjects;
using System.Diagnostics;
using System.Reactive.Subjects;
using Microsoft.Extensions.DependencyInjection;

namespace Totoro.Core.Services;
Expand Down
2 changes: 1 addition & 1 deletion Totoro.WinUI/Helpers/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static MenuFlyout AnimeToFlyout(AnimeModel anime)
Text = @"Info",
Command = App.Commands.More,
CommandParameter = anime.Id,
Icon = new FontIcon() { Glyph = "\uEC15" }
Icon = new FontIcon() { Glyph = "\uE946" }
});

return flyout;
Expand Down
2 changes: 1 addition & 1 deletion Totoro.WinUI/Views/ShellPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<NavigationViewItem
helpers:NavigationHelper.NavigateTo="Totoro.Core.ViewModels.AboutAnimeViewModel"
Content="About"
Icon="Document"
Icon="{ui:FontIcon Glyph=&#xE946;}"
Visibility="{x:Bind help:Converters.BooleanToVisibility(ViewModel.IsAboutView), Mode=OneWay}" />
<NavigationViewItem
helpers:NavigationHelper.NavigateTo="Totoro.WinUI.ViewModels.NowPlayingViewModel"
Expand Down

0 comments on commit 16c712d

Please sign in to comment.