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

cache visitor ID on first use #738

Merged
merged 1 commit into from
Feb 4, 2025
Merged

Conversation

sgvictorino
Copy link
Contributor

@sgvictorino sgvictorino commented Feb 3, 2025

import ytmusicapi
import timeit

yt = ytmusicapi.YTMusic()
for _ in range(2):
  print(round(timeit.timeit(lambda: yt.get_album('MPREb_4pL8gzRtw1p'), number=1) * 1000))

-710
-593
+753
+146

@sigma67
Copy link
Owner

sigma67 commented Feb 3, 2025

Wouldn't it make more sense to move it into base_headers if it shouldn't be updated? Those could be turned into cached_property

@sgvictorino
Copy link
Contributor Author

If I understand correctly, base_headers is used for fetching the visitor ID.

@sigma67
Copy link
Owner

sigma67 commented Feb 4, 2025

Does the suggested solution work for you? Sorry for the breakage caused by the refactor.

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.14%. Comparing base (334798f) to head (768ec03).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #738      +/-   ##
==========================================
- Coverage   95.14%   95.14%   -0.01%     
==========================================
  Files          41       41              
  Lines        2410     2409       -1     
==========================================
- Hits         2293     2292       -1     
  Misses        117      117              
Flag Coverage Δ
unittests 95.14% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sgvictorino
Copy link
Contributor Author

It works. Thanks!

@sigma67 sigma67 merged commit c60950a into sigma67:main Feb 4, 2025
5 checks passed
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.

2 participants