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.Encoding;
|
||||||
using Roadie.Library.Engines;
|
using Roadie.Library.Engines;
|
||||||
using Roadie.Library.Enums;
|
using Roadie.Library.Enums;
|
||||||
|
using Roadie.Library.Extensions;
|
||||||
using Roadie.Library.Factories;
|
using Roadie.Library.Factories;
|
||||||
using Roadie.Library.Identity;
|
using Roadie.Library.Identity;
|
||||||
using Roadie.Library.MetaData.Audio;
|
using Roadie.Library.MetaData.Audio;
|
||||||
|
@ -357,58 +358,67 @@ namespace Roadie.Api.Services
|
||||||
{
|
{
|
||||||
var now = DateTime.UtcNow;
|
var now = DateTime.UtcNow;
|
||||||
foreach (var csvRelease in par)
|
foreach (var csvRelease in par)
|
||||||
{
|
{
|
||||||
data.Release release = null;
|
|
||||||
CollectionRelease isInCollection = null;
|
|
||||||
OperationResult<data.Release> releaseResult = null;
|
|
||||||
data.Artist artist = null;
|
data.Artist artist = null;
|
||||||
var artistResult = await this.ArtistLookupEngine.GetByName(new AudioMetaData { Artist = csvRelease.Artist });
|
data.Release release = null;
|
||||||
if (!artistResult.IsSuccess)
|
|
||||||
|
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;
|
csvRelease.Status = Library.Enums.Statuses.Missing;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else
|
foreach (var artistResult in artistResults)
|
||||||
{
|
{
|
||||||
artist = artistResult.Data;
|
artist = artistResult;
|
||||||
}
|
searchName = csvRelease.Release.NormalizeName().ToLower();
|
||||||
if (artist != null)
|
specialSearchName = csvRelease.Release.ToAlphanumericName();
|
||||||
{
|
release = (from r in this.DbContext.Releases
|
||||||
releaseResult = await this.ReleaseLookupEngine.GetByName(artist, new AudioMetaData { Release = csvRelease.Release });
|
where (r.ArtistId == artist.Id)
|
||||||
if (!releaseResult.IsSuccess)
|
where (r.Title.Contains(searchName) ||
|
||||||
|
r.AlternateNames.Contains(searchName) ||
|
||||||
|
r.AlternateNames.Contains(specialSearchName))
|
||||||
|
select r
|
||||||
|
).FirstOrDefault();
|
||||||
|
if(release != null)
|
||||||
{
|
{
|
||||||
this.Logger.LogWarning("Unable To Find Release [{0}]", csvRelease.Release);
|
break;
|
||||||
csvRelease.Status = Library.Enums.Statuses.Missing;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (releaseResult != null)
|
if (release == null)
|
||||||
{
|
{
|
||||||
release = releaseResult.Data;
|
this.Logger.LogWarning("Unable To Find Release [{0}], SearchName [{1}]", csvRelease.Release, searchName);
|
||||||
}
|
csvRelease.Status = Library.Enums.Statuses.Missing;
|
||||||
if (artist != null && release != null)
|
continue;
|
||||||
|
}
|
||||||
|
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)
|
||||||
{
|
{
|
||||||
isInCollection = this.DbContext.CollectionReleases.FirstOrDefault(x => x.CollectionId == collection.Id && x.ListNumber == csvRelease.Position && x.ReleaseId == release.Id);
|
this.DbContext.CollectionReleases.Add(new CollectionRelease
|
||||||
// Found in Database but not in collection add to Collection
|
|
||||||
if (isInCollection == null)
|
|
||||||
{
|
{
|
||||||
this.DbContext.CollectionReleases.Add(new CollectionRelease
|
CollectionId = collection.Id,
|
||||||
{
|
ReleaseId = release.Id,
|
||||||
CollectionId = collection.Id,
|
ListNumber = csvRelease.Position,
|
||||||
ReleaseId = release.Id,
|
});
|
||||||
ListNumber = csvRelease.Position,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// If Item in Collection is at different List number update CollectionRelease
|
|
||||||
else if (isInCollection.ListNumber != csvRelease.Position)
|
|
||||||
{
|
|
||||||
isInCollection.LastUpdated = now;
|
|
||||||
isInCollection.ListNumber = csvRelease.Position;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
// If Item in Collection is at different List number update CollectionRelease
|
||||||
|
else if (isInCollection.ListNumber != csvRelease.Position)
|
||||||
{
|
{
|
||||||
this.Logger.LogWarning("Unable To Find Artist Or Release For Collection Entry [{0}]", csvRelease.ToString());
|
isInCollection.LastUpdated = now;
|
||||||
result.Add(csvRelease);
|
isInCollection.ListNumber = csvRelease.Position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
collection.LastUpdated = now;
|
collection.LastUpdated = now;
|
||||||
|
|
Loading…
Reference in a new issue