Skip to content

Commit

Permalink
New Scan Loop Fixes (Kareadita#1452)
Browse files Browse the repository at this point in the history
* Refactored ScanSeries to avoid a lot of extra work and fixed a bug where Scan Series would invoke the processing twice.

Refactored the series selection code during process such that we use Localized Name as well, for cases where the original name was changed.

Undid an optimization around Last Write time, since Linux file systems match how NTFS works.

* Fixed part of the query

* Added a NormalizedLocalizedName for quick searching in which a series needs grouping. Reworked scan loop code a bit to ensure we don't do extra work.

Tweaked the widget logic to help display better and not show "Nothing going on here".

* Fixed a bug where archives with ._ files would be counted as valid files, while they are actually just metadata files on Mac's.

* Fixed a broken unit test
  • Loading branch information
majora2007 authored Aug 20, 2022
1 parent 252f31d commit 7cb547f
Show file tree
Hide file tree
Showing 17 changed files with 1,815 additions and 65 deletions.
1 change: 1 addition & 0 deletions API.Tests/Services/ArchiveServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void IsValidArchiveTest(string archivePath, bool expected)
[InlineData("macos_none.zip", 0)]
[InlineData("macos_one.zip", 1)]
[InlineData("macos_native.zip", 21)]
[InlineData("macos_withdotunder_one.zip", 1)]
public void GetNumberOfPagesFromArchiveTest(string archivePath, int expected)
{
var testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService/Archives");
Expand Down
Binary file not shown.
2 changes: 2 additions & 0 deletions API/Controllers/SeriesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ await _unitOfWork.SeriesRepository.DoesSeriesNameExistInLibrary(updateSeries.Nam
}

series.Name = updateSeries.Name.Trim();
series.NormalizedName = Parser.Parser.Normalize(series.Name);
if (!string.IsNullOrEmpty(updateSeries.SortName.Trim()))
{
series.SortName = updateSeries.SortName.Trim();
}

series.LocalizedName = updateSeries.LocalizedName.Trim();
series.NormalizedLocalizedName = Parser.Parser.Normalize(series.LocalizedName);

series.NameLocked = updateSeries.NameLocked;
series.SortNameLocked = updateSeries.SortNameLocked;
Expand Down
38 changes: 38 additions & 0 deletions API/Data/MigrateNormalizedLocalizedName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;

namespace API.Data;

/// <summary>
/// v0.5.6 introduced Normalized Localized Name, which allows for faster lookups and less memory usage. This migration will calculate them once
/// </summary>
public static class MigrateNormalizedLocalizedName
{
public static async Task Migrate(IUnitOfWork unitOfWork, DataContext dataContext, ILogger<Program> logger)
{
if (!await dataContext.Series.Where(s => s.NormalizedLocalizedName == null).AnyAsync())
{
return;
}
logger.LogInformation("Running MigrateNormalizedLocalizedName migration. Please be patient, this may take some time");


foreach (var series in await dataContext.Series.ToListAsync())
{
series.NormalizedLocalizedName = Parser.Parser.Normalize(series.LocalizedName ?? string.Empty);
logger.LogInformation("Updated {SeriesName} normalized localized name: {LocalizedName}", series.Name, series.NormalizedLocalizedName);
unitOfWork.SeriesRepository.Update(series);
}

if (unitOfWork.HasChanges())
{
await unitOfWork.CommitAsync();
}

logger.LogInformation("MigrateNormalizedLocalizedName migration finished");

}

}
Loading

0 comments on commit 7cb547f

Please sign in to comment.