edrlab / thorium-reader

A cross platform desktop reading app, based on the Readium Desktop toolkit
https://www.edrlab.org/software/thorium-reader/
BSD 3-Clause "New" or "Revised" License
1.64k stars 145 forks source link

readingFinished refresh flag consume too much cpu load on reader and library #2144

Closed panaC closed 1 month ago

panaC commented 2 months ago

https://github.com/edrlab/thorium-reader/commit/08b2c3c49ae976b811b805238c7bb020f6325208#r141722337

danielweck commented 2 months ago

https://github.com/edrlab/thorium-reader/blob/08b2c3c49ae976b811b805238c7bb020f6325208/src/renderer/reader/components/Reader.tsx#L2825-L2830

https://github.com/edrlab/thorium-reader/blob/08b2c3c49ae976b811b805238c7bb020f6325208/src/renderer/reader/components/Reader.tsx#L2214-L2216

https://github.com/edrlab/thorium-reader/blob/08b2c3c49ae976b811b805238c7bb020f6325208/src/renderer/reader/components/Reader.tsx#L2223-L2235

https://github.com/edrlab/thorium-reader/blob/08b2c3c49ae976b811b805238c7bb020f6325208/src/renderer/reader/components/Reader.tsx#L540

setLocator is called whenever TTS or Media Overlays audio playback is ongoing, which can flood the DB backend and React GUI with update requests unless throttled (debounced on leading edge would yield out-of-sync states especially if no leading edge terminator, and debounced on leading edge only would also cause massive refresh delays ... so throttle is probably the most reasonable / practical solution)

danielweck commented 2 months ago

So, to keep things simple, maybe just throttle the call to apiDispatch(dispatch)()("publication/readingFinishedRefresh") only?