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

Performance: Use totalSize attribute for watchlist walking #1070

Merged
merged 1 commit into from
Dec 21, 2022

Conversation

glensc
Copy link
Contributor

@glensc glensc commented Dec 20, 2022

Description

I noticed watchlist walking xml contains totalSize attribute. This could be used to know if next page should be fetched.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the docstring for new or existing methods
  • I have added tests when applicable

@JonnyWong16
Copy link
Collaborator

I'm not sure this make any difference to performance. The loop will stop when there are no more subresults anyways.

Check the PlexAPI log file to count the number of API calls and see if there is any difference.

@glensc
Copy link
Contributor Author

glensc commented Dec 20, 2022

I came to this code after inspecting logs, so...

And no, it makes an extra call with no results that stopped the loop. This pr omits that last empty call.

EDIT: I may try to test again maybe I miss-tested as it was late already. Tested: #1070 (comment)

@glensc
Copy link
Contributor Author

glensc commented Dec 20, 2022

this branch:

python-plexapi (watchlist-totalSize) ➜ python test_watchlist.py
2022-12-20 20:26:00,933:plexapi: GET https://*redacted*.plex.direct:32400/
2022-12-20 20:26:01,021:plexapi: GET https://plex.tv/users/account
2022-12-20 20:26:01,706:plexapi: GET https://metadata.provider.plex.tv/library/sections/watchlist/all
2022-12-20 20:26:03,176:plexapi: GET https://metadata.provider.plex.tv/
Watchlist size: 30

master branch:

python-plexapi (master) ➜ python test_watchlist.py
2022-12-20 20:26:07,458:plexapi: GET https://*redacted*.plex.direct:32400/
2022-12-20 20:26:07,551:plexapi: GET https://plex.tv/users/account
2022-12-20 20:26:07,815:plexapi: GET https://metadata.provider.plex.tv/library/sections/watchlist/all
2022-12-20 20:26:08,229:plexapi: GET https://metadata.provider.plex.tv/library/sections/watchlist/all
2022-12-20 20:26:08,510:plexapi: GET https://metadata.provider.plex.tv/
Watchlist size: 30

code

from plexapi.server import PlexServer


def test_myplex_watchlist(env):
    url = env.get('PLEX_URL')
    token = env.get('PLEX_TOKEN')
    plex = PlexServer(baseurl=url, token=token)
    account = plex.myPlexAccount()
    watchlist = account.watchlist()

    print(f"Watchlist size: {len(watchlist)}")


if __name__ == "__main__":
    import os
    import logging

    from plexapi import log as logger
    from plexapi import loghandler

    logger.removeHandler(loghandler)
    logger.setLevel(logging.DEBUG)
    logging.basicConfig(format="%(asctime)s:%(name)s: %(message)s")

    test_myplex_watchlist(os.environ)

@JonnyWong16
Copy link
Collaborator

Okay, it saves one extra call at the end to check there are no more items.

@JonnyWong16 JonnyWong16 changed the title Performance: Use totalSize attribute for watchlist walking Performance: Use totalSize attribute for watchlist walking Dec 21, 2022
@JonnyWong16 JonnyWong16 merged commit c3d2a56 into pkkid:master Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants