Skip to content

Commit

Permalink
Log dedup decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Guerra24 committed Sep 23, 2023
1 parent 90281ae commit ff22fac
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion LRReader.Shared/LRReader.Shared.csproj
Expand Up @@ -24,7 +24,7 @@
</PackageReference>
<PackageReference Include="RestSharp" Version="110.2.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="110.2.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.4" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.6" />
</ItemGroup>

</Project>
35 changes: 21 additions & 14 deletions LRReader.Shared/Tools/Deduplicator.cs
Expand Up @@ -10,6 +10,7 @@
using LRReader.Shared.Models.Main;
using LRReader.Shared.Providers;
using LRReader.Shared.Services;
using Microsoft.Extensions.Logging;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
Expand Down Expand Up @@ -57,13 +58,15 @@ public class DeduplicationTool : Tool<DeduplicatorStatus, DeduplicatorParams, Li
private readonly ImagesService Images;
private readonly ArchivesService Archives;
private readonly PlatformService Platform;
private readonly ILogger<DeduplicationTool> Logger;

public DeduplicationTool(SettingsService settings, ImagesService images, ArchivesService archives, PlatformService platform) : base(platform)
public DeduplicationTool(SettingsService settings, ImagesService images, ArchivesService archives, PlatformService platform, ILogger<DeduplicationTool> logger) : base(platform)
{
Settings = settings;
Images = images;
Archives = archives;
Platform = platform;
Logger = logger;
}

protected override async Task<ToolResult<List<ArchiveHit>, List<string>>> Process(DeduplicatorParams @params, int threads)
Expand Down Expand Up @@ -100,30 +103,34 @@ public DeduplicationTool(SettingsService settings, ImagesService images, Archive
{
int tries = 5;
Image<Rgb24>? image = null;
while (tries > 0)
try
{
Thread.Sleep(delay * (6 - tries)); // TODO Good ol' Thread.Sleep
var bytes = Task.Run(async () => await Images.GetThumbnailCached(pair.Key)).GetAwaiter().GetResult();
if (bytes != null)
while (tries > 0)
{
try
Thread.Sleep(delay * (6 - tries)); // TODO Good ol' Thread.Sleep
Logger.LogInformation("LoadThumb {0} {1}", pair.Key, tries);
var bytes = Images.GetThumbnailCached(pair.Key).ConfigureAwait(false).GetAwaiter().GetResult();
if (bytes != null)
{
image = Image.Load<Rgb24>(bytes);
image.Mutate(i => i.Resize(width, 0));
break;
}
else
{
tries--;
}
catch { }
break;
}
else
int itemCount = Interlocked.Increment(ref count);
if (DateTime.Now - tmpTimer > TimeSpan.FromSeconds(1))
{
tries--;
tmpTimer = DateTime.Now;
UpdateProgress(DeduplicatorStatus.PreloadAndDecode, archives.Count, itemCount);
}
}
int itemCount = Interlocked.Increment(ref count);
if (DateTime.Now - tmpTimer > TimeSpan.FromSeconds(1))
catch (Exception e)
{
tmpTimer = DateTime.Now;
UpdateProgress(DeduplicatorStatus.PreloadAndDecode, archives.Count, itemCount);
Logger.LogInformation(e, "LoadThumb {0}", pair.Key);
}
return new Tuple<string, Image<Rgb24>?>(pair.Key, image);
})))).AsEnumerable().ToList();
Expand Down
2 changes: 1 addition & 1 deletion LRReader.UWP.Installer/LRReader.UWP.Installer.csproj
Expand Up @@ -33,7 +33,7 @@
</PackageReference>
<PackageReference Include="Microsoft.Windows.SDK.Contracts" Version="10.0.22621.755" />
<PackageReference Include="WPF-UI">
<Version>3.0.0-preview.4</Version>
<Version>3.0.0-preview.6</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion LRReader.UWP.Installer/MainWindow.xaml.cs
Expand Up @@ -56,7 +56,7 @@ public MainWindow()

private async void Window_Loaded(object sender, RoutedEventArgs e)
{
Watcher.Watch(this, WindowBackdropType.Mica, true);
SystemThemeWatcher.Watch(this, WindowBackdropType.Mica, true);
if (Environment.OSVersion.Version < new Version(10, 0, 17763, 0))
{
Error.Text = "LRReader requires Windows 10 1809 or newer";
Expand Down
2 changes: 1 addition & 1 deletion LRReader.UWP/LRReader.UWP.csproj
Expand Up @@ -440,7 +440,7 @@
<Version>2.8.2-prerelease.220830001</Version>
</PackageReference>
<PackageReference Include="Microsoft.Web.WebView2">
<Version>1.0.1823.32</Version>
<Version>1.0.2045.28</Version>
</PackageReference>
<PackageReference Include="Nullable">
<Version>1.3.1</Version>
Expand Down
2 changes: 1 addition & 1 deletion LRReader.UWP/Services/Platform.cs
Expand Up @@ -52,7 +52,7 @@ public UWPlatformService(TabsService tabs, ILoggerFactory loggerFactory, IFilesS

MapTransitionToType(PagesTransition.None, typeof(SuppressNavigationTransitionInfo));
MapTransitionToType(PagesTransition.DrillIn, typeof(DrillInNavigationTransitionInfo));
#if DEBUG
#if DEBUG || NIGHTLY
loggerFactory.AddFile(files.LocalCache + string.Format("/Logs/{0:yyyy}-{0:MM}-{0:dd}.log", DateTime.UtcNow));
#endif
}
Expand Down

0 comments on commit ff22fac

Please sign in to comment.