fxsth / pledo

pledo - Plex downloader. An alternative to PlexRipper
MIT License
17 stars 3 forks source link

Unable to get past initial "sync all metadata now" #18

Closed Chopp3rDave closed 1 year ago

Chopp3rDave commented 1 year ago

I have 5 shared servers in addition to my own server. Trying to do the initial "Sync all metadata now" however I consistently get an error such as:

fail: Web.Services.SyncService[0]
      An unexpected error occured while syncing:
      System.InvalidOperationException: The instance of entity type 'MediaFile' cannot be tracked because another instance with the same key value for {'DownloadUri'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values.
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.ThrowIdentityConflict(InternalEntityEntry entry)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.IdentityMap`1.Add(TKey key, InternalEntityEntry entry, Boolean updateDuplicate)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.StartTracking(InternalEntityEntry entry)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState oldState, EntityState newState, Boolean acceptChanges, Boolean modifyProperties)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityState(EntityState entityState, Boolean acceptChanges, Boolean modifyProperties, Nullable`1 forceStateWhenUnknownKey, Nullable`1 fallbackState)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintAction(EntityEntryGraphNode`1 node)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraph[TState](EntityEntryGraphNode`1 node, Func`2 handleNode)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState targetState, EntityState storeGeneratedWithKeySetTargetState, Boolean forceStateWhenUnknownKey)
         at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.SetEntityState(InternalEntityEntry entry, EntityState entityState)
         at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.SetEntityStates(IEnumerable`1 entities, EntityState entityState)
         at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.AddRange(IEnumerable`1 entities)
         at Web.Data.EpisodeRepository.Upsert(IEnumerable`1 t) in /src/Web/Data/EpisodeRepository.cs:line 36
         at Web.Data.EpisodeRepository.Upsert(IEnumerable`1 t) in /src/Web/Data/EpisodeRepository.cs:line 23
         at Web.Services.SyncService.UpsertMediaIntoDb(UnitOfWork unitOfWork, IReadOnlyCollection`1 movies, IReadOnlyCollection`1 episodes) in /src/Web/Services/SyncService.cs:line 84
         at Web.Services.SyncService.Sync(SyncType syncType) in /src/Web/Services/SyncService.cs:line 56

As there isn't any way to selectively choose which servers (or libraries) to sync, I'm unable to use the app. I'm not seeing any other way to get past this. If I can provide any further information, please let me know.

fxsth commented 1 year ago

The logs seem to report a key conflict, probably caused by same ids on different servers. There is a change in the database now, which should fix this. Can you try again with the new release 1.2.1?

Chopp3rDave commented 1 year ago

Thanks for that, I was able to get past the initial scan. However, I opened a fairly large TV library, and got the following warning which seems accurate as the load time is over 10+ min and still hasn't opened:

warn: Microsoft.EntityFrameworkCore.Query[20504] Compiling a query which loads related collections for more than one collection navigation, either via 'Include' or through projection, but no 'QuerySplittingBehavior' has been configured. By default, Entity Framework will use 'QuerySplittingBehavior.SingleQuery', which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'.

fxsth commented 1 year ago

I'm glad this release fixed your initial problem. And you're right, there might be potential to optimize the sync speed. I think the query behaviour is only one of the things to do. Just to relate to some numbers, what scale is 'a fairly large TV library'?

Chopp3rDave commented 1 year ago

This specific library was 373 tv shows.

fxsth commented 1 year ago

There might be a decent performance boost in the next release by trying also http connections. That should speed the sync a little bit up. Query behaviour is still an open task to improve. I'll close this issue for now, feel free to open a new one if there are issues.