AnkiHubSoftware / ankihub_addon

1 stars 0 forks source link

[BUILD-439] perf: Prevent Anki being laggy while downloading media #972

Closed RisingOrange closed 3 months ago

RisingOrange commented 3 months ago

Some users are experiencing Anki being laggy when the AnkiHub media sync is in progress.

This PR addresses the problem by:

Related issues

https://ankihub.atlassian.net/jira/software/c/projects/BUILD/boards/1?selectedIssue=BUILD-439 https://theanking.slack.com/archives/C03S5DH9HH9/p1717080091231869

Proposed changes

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 87.51%. Comparing base (14d9af6) to head (3538b11). Report is 6 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #972 +/- ## ========================================== + Coverage 87.41% 87.51% +0.10% ========================================== Files 66 66 Lines 6642 6697 +55 ========================================== + Hits 5806 5861 +55 Misses 836 836 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

RisingOrange commented 3 months ago

@andrewsanchez Good points!

I changed the client to use one Session for each thread. The Session is re-used for requests on that thread.

The performance improvements from using a Session properly will depend on us instantiating the client only once when it is being used for multiple requests.

This is now the case, at least when downloading and uploading media (where it matters most). AnkiHubClient.download_media takes the list of all media names that need to be downloaded, so everything will be handled by one client instance. The same goes for AnkiHubClient.upload_media.

sentry-io[bot] commented 3 months ago

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

Did you find this useful? React with a 👍 or 👎