Skip to content

Commit

Permalink
MP2-858 Also update existing relations when no new relations are formed
Browse files Browse the repository at this point in the history
  • Loading branch information
henso96 committed Jan 5, 2021
1 parent 2f1316c commit 7ecaaf4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2028,25 +2028,21 @@ private Guid AddOrUpdateMediaItem(ISQLDatabase database, ITransaction transactio
return mediaItemId;
}

public IList<MediaItem> ReconcileMediaItemRelationships(Guid mediaItemId, IEnumerable<MediaItemAspect> mediaItemAspects,
IEnumerable<RelationshipItem> relationshipItems)
public IList<MediaItem> ReconcileMediaItemRelationships(Guid mediaItemId, IEnumerable<MediaItemAspect> mediaItemAspects, IEnumerable<RelationshipItem> relationshipItems)
{
Stopwatch swImport = new Stopwatch();
swImport.Start();
var relationships = relationshipItems.ToList();
string name = GetMediaItemTitle(mediaItemAspects, "");
List<MediaItem> result = new List<MediaItem>();
if (relationships.Any())
if (relationshipItems != null)
{
IDictionary<Guid, IList<MediaItemAspect>> aspects = MediaItemAspect.GetAspects(mediaItemAspects);
IEnumerable<IRelationshipRoleExtractor> itemMatchers =
ServiceRegistration.Get<IMediaAccessor>().LocalRelationshipExtractors.Values.SelectMany(r => r.RoleExtractors).ToArray();

IEnumerable<IRelationshipRoleExtractor> itemMatchers = ServiceRegistration.Get<IMediaAccessor>().LocalRelationshipExtractors.Values.SelectMany(r => r.RoleExtractors).ToArray();
HashSet<Guid> updatedItemIds = new HashSet<Guid>();
ISQLDatabase database = ServiceRegistration.Get<ISQLDatabase>();
using (ITransaction transaction = database.BeginTransaction())
{
foreach (var item in relationships)
foreach (var item in relationshipItems)
{
IRelationshipRoleExtractor itemMatcher = itemMatchers.FirstOrDefault(r => r.Role == item.Role && r.LinkedRole == item.LinkedRole);
if (itemMatcher == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ protected async Task<ICollection<MediaItem>> ReconcileRelationships(Guid mediaIt
if (relations.Count == 0)
{
// Inform media library that there are no relationships
await ReconcileMediaItemRelationships(mediaItemId, MediaItemAspect.GetAspects(aspects), new List<RelationshipItem>()).ConfigureAwait(false);
await ReconcileMediaItemRelationships(mediaItemId, MediaItemAspect.GetAspects(aspects), null).ConfigureAwait(false);
return newMediaItems;
}

Expand Down

0 comments on commit 7ecaaf4

Please sign in to comment.