AwesomeTTS / awesometts-anki-addon

AwesomeTTS text-to-speech add-on for Anki
GNU General Public License v3.0
483 stars 100 forks source link

Anki takes about 2 minutes to close because it is doing some search on the audio cache directory #231

Open evandrocoan opened 3 years ago

evandrocoan commented 3 years ago

Originally posted: https://github.com/ankitects/anki/pull/1363#issuecomment-919592713

This addon has registered the hook Hook(name="profile_will_close", legacy_hook="unloadProfile"),:

  1. https://github.com/AwesomeTTS/awesometts-anki-addon/blob/e056fc700cbf653eca152615caf76b9166cead04/awesometts/__init__.py#L481-L500
  2. https://github.com/AwesomeTTS/awesometts-anki-addon/blob/e056fc700cbf653eca152615caf76b9166cead04/awesometts/__init__.py#L788-L807

It is doing some search on the file system and depending on how many audios I have cached or saved, it can take a long time to complete.

I got 14.000 files in my cache directory (over an old HD) and this makes Anki too about 2 minutes to close:

2021-10-11 21:21:05.536109 Starting unloadProfileAndExit
2021-10-11 21:21:05.536109 Starting gui_hooks.profile_will_close()
here
2021-10-11 21:23:30.857553 Ending gui_hooks.profile_will_close()
2021-10-11 21:23:30.868554 Starting closeAll
2021-10-11 21:23:30.876555 After self.allClosed

image

luc-vocab commented 3 years ago

thanks for reporting this, I'm going to look into it. just curious, we've had many users reporting that addon upgrades result in wiping out the cache directory, how are you not impacted by this, you have your own git checkout of awesometts ?

evandrocoan commented 3 years ago

Yes, I do. All my Anki add-ons are just a git repository (with submodules for the addons I can fork on GitHub): https://github.com/evandrocoan/AnkiAddons

I just cleaned out my cache dir and the slowness at the close was fixed. Perhaps cleaning the directory after 1000 entries would be the solution?

luc-vocab commented 3 years ago

Well it turns out some people highly treasure their cache directory and get very upset when it gets cleaned out. I guess they sign up for an API key on azure or google as a one time thing and then pre-cache all their audio. So I need to give this some thought.

lovac42 commented 3 years ago

2.1.3x comes with a background task manager (although untested in practice). You could move some of those code to background tasks on a separate thread, limiting this to one scan every 24hrs on startup should be enough.

evandrocoan commented 3 years ago

I actually undeleted my cache directory because it was causing AwesomeTTS to create duplicate audio files as ATTS ボク モク(google ja).mp3 and ATTS ボク モク(google ja)-5568d833959b394ab4c2a45068048505300ffbd1.mp3.