mirror of
https://github.com/sphildreth/roadie
synced 2024-11-10 06:44:12 +00:00
Reworked collection scan for performance.
This commit is contained in:
parent
6a985a7316
commit
932f7b6987
1 changed files with 49 additions and 39 deletions
|
@ -10,6 +10,7 @@ using Roadie.Library.Data;
|
|||
using Roadie.Library.Encoding;
|
||||
using Roadie.Library.Engines;
|
||||
using Roadie.Library.Enums;
|
||||
using Roadie.Library.Extensions;
|
||||
using Roadie.Library.Factories;
|
||||
using Roadie.Library.Identity;
|
||||
using Roadie.Library.MetaData.Audio;
|
||||
|
@ -358,36 +359,51 @@ namespace Roadie.Api.Services
|
|||
var now = DateTime.UtcNow;
|
||||
foreach (var csvRelease in par)
|
||||
{
|
||||
data.Release release = null;
|
||||
CollectionRelease isInCollection = null;
|
||||
OperationResult<data.Release> releaseResult = null;
|
||||
|
||||
data.Artist artist = null;
|
||||
var artistResult = await this.ArtistLookupEngine.GetByName(new AudioMetaData { Artist = csvRelease.Artist });
|
||||
if (!artistResult.IsSuccess)
|
||||
data.Release release = null;
|
||||
|
||||
var searchName = csvRelease.Artist.NormalizeName();
|
||||
var specialSearchName = csvRelease.Artist.ToAlphanumericName();
|
||||
|
||||
var artistResults = (from a in this.DbContext.Artists
|
||||
where (a.Name.Contains(searchName) ||
|
||||
a.SortName.Contains(searchName) ||
|
||||
a.AlternateNames.Contains(searchName) ||
|
||||
a.AlternateNames.Contains(specialSearchName))
|
||||
select a).ToArray();
|
||||
if (!artistResults.Any())
|
||||
{
|
||||
this.Logger.LogWarning("Unable To Find Artist [{0}]", csvRelease.Artist);
|
||||
this.Logger.LogWarning("Unable To Find Artist [{0}], SearchName [{1}]", csvRelease.Artist, searchName);
|
||||
csvRelease.Status = Library.Enums.Statuses.Missing;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
foreach (var artistResult in artistResults)
|
||||
{
|
||||
artist = artistResult.Data;
|
||||
artist = artistResult;
|
||||
searchName = csvRelease.Release.NormalizeName().ToLower();
|
||||
specialSearchName = csvRelease.Release.ToAlphanumericName();
|
||||
release = (from r in this.DbContext.Releases
|
||||
where (r.ArtistId == artist.Id)
|
||||
where (r.Title.Contains(searchName) ||
|
||||
r.AlternateNames.Contains(searchName) ||
|
||||
r.AlternateNames.Contains(specialSearchName))
|
||||
select r
|
||||
).FirstOrDefault();
|
||||
if(release != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (artist != null)
|
||||
}
|
||||
if (release == null)
|
||||
{
|
||||
releaseResult = await this.ReleaseLookupEngine.GetByName(artist, new AudioMetaData { Release = csvRelease.Release });
|
||||
if (!releaseResult.IsSuccess)
|
||||
{
|
||||
this.Logger.LogWarning("Unable To Find Release [{0}]", csvRelease.Release);
|
||||
this.Logger.LogWarning("Unable To Find Release [{0}], SearchName [{1}]", csvRelease.Release, searchName);
|
||||
csvRelease.Status = Library.Enums.Statuses.Missing;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (releaseResult != null)
|
||||
{
|
||||
release = releaseResult.Data;
|
||||
}
|
||||
if (artist != null && release != null)
|
||||
{
|
||||
isInCollection = this.DbContext.CollectionReleases.FirstOrDefault(x => x.CollectionId == collection.Id && x.ListNumber == csvRelease.Position && x.ReleaseId == release.Id);
|
||||
var isInCollection = this.DbContext.CollectionReleases.FirstOrDefault(x => x.CollectionId == collection.Id &&
|
||||
x.ListNumber == csvRelease.Position &&
|
||||
x.ReleaseId == release.Id);
|
||||
// Found in Database but not in collection add to Collection
|
||||
if (isInCollection == null)
|
||||
{
|
||||
|
@ -405,12 +421,6 @@ namespace Roadie.Api.Services
|
|||
isInCollection.ListNumber = csvRelease.Position;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Logger.LogWarning("Unable To Find Artist Or Release For Collection Entry [{0}]", csvRelease.ToString());
|
||||
result.Add(csvRelease);
|
||||
}
|
||||
}
|
||||
collection.LastUpdated = now;
|
||||
await this.DbContext.SaveChangesAsync();
|
||||
var dto = new Library.Models.Collections.CollectionList
|
||||
|
|
Loading…
Reference in a new issue