Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor metadata ancestor gathering #362

Merged
merged 5 commits into from Aug 18, 2020

Conversation

mcarlton00
Copy link
Member

Kinda fixes #361. Some of it just can't be helped. We don't need to find ancestors on userdata updates. If the item exists, it's updated. If it doesn't, it gets skipped. No need to do the intensive lookup process.

I'm not sure the Artist/Album bits of the userdata updates are ever triggered. At least I haven't seen it in my testing, but I'm not confident enough to remove it yet.

Also changes

Music(*default_args).song(item)

to

Music(*default_args).userdata(item)

We don't want to try to add new items whenever a song is listened to

@TrueTechy
Copy link
Contributor

Getting errors trying to do the initial sync

2020-08-14 23:58:38.989 T:140495737046784  NOTICE: JELLYFIN.library -> ERROR::jellyfin_kodi/library.py:367 unsupported operand type(s) for /: 'unicode' and 'float'
                                            Traceback (most recent call last):
                                              File "jellyfin_kodi/library.py", line 324, in startup
                                                sync.libraries()
                                              File "jellyfin_kodi/full_sync.py", line 101, in libraries
                                                self.start()
                                              File "jellyfin_kodi/full_sync.py", line 186, in start
                                                self.process_library(library)
                                              File "jellyfin_kodi/full_sync.py", line 243, in process_library
                                                media[library['CollectionType']](library)
                                              File "jellyfin_kodi/helper/wrapper.py", line 41, in wrapper
                                                result = func(self, dialog=dialog, *args, **kwargs)
                                              File "jellyfin_kodi/full_sync.py", line 386, in musicvideos
                                                obj.musicvideo(mvideo)
                                              File "jellyfin_kodi/helper/wrapper.py", line 65, in wrapper
                                                return func(*args, **kwargs)
                                              File "jellyfin_kodi/helper/wrapper.py", line 77, in wrapper
                                                return func(self, item, e_item=e_item, *args, **kwargs)
                                              File "jellyfin_kodi/objects/musicvideos.py", line 82, in musicvideo
                                                obj['Resume'] = API.adjust_resume((obj['Resume'] or 0) / 10000000.0)
                                            TypeError: unsupported operand type(s) for /: 'unicode' and 'float'

@mcarlton00 mcarlton00 changed the title Don't find ancestors on userdata updates Refactor metadata ancestor gathering Aug 15, 2020
@mcarlton00
Copy link
Member Author

I'm not sure the referenced error is caused by this PR. Or at least I can't imagine how it would be. Stranger things have certainly happened in this code base, though.

Fixes #361 more gooder now.

Part 1 was moving the find_library() function from library.py into each individual function. While it's easier to understand in library.py, it's effectively causing 1-2 seconds per item in the incremental sync. Which is an pretty major annoyance if you run into a case like I had with ~600 items changed.

The jellyfin_item() wrapper on each media object looks up the item in the local database and pulls various information from it, including the LibraryId of the object (stores this metadata in the e_item variable). For reasons unknown, LibraryId wasn't ever included for Albums and Audio files. When the LibraryId (or the DB entry entirely) can't be found, it falls back into the find_library() function that checks the server for ancestors and takes 1-2 seconds to complete, so obviously it's better to pull this info from the database instead.

This changes the query so that any future modified Albums/Audio files get the LibraryId added to it's entry in the local database. However doing it this way means that incremental syncs that touch the un-modified entries are still rather slow. We should recommend running a manual sync on music libraries so users don't see a big delay more than necessary.

jellyfin_kodi/library.py Outdated Show resolved Hide resolved
Co-authored-by: Odd Stråbø <oddstr13@openshell.no>
@sonarcloud
Copy link

sonarcloud bot commented Aug 18, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@oddstr13 oddstr13 merged commit 8b1b648 into jellyfin:master Aug 18, 2020
@oddstr13 oddstr13 mentioned this pull request Aug 25, 2020
@mcarlton00 mcarlton00 deleted the might've-used-too-much branch April 3, 2022 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incremental sync very slow
3 participants