Open jneumaier opened 3 years ago
I agree that this is not optimal. PR welcomed.
But instead of managing timeout I suggest to stat this file often (like every second or a few seconds), but read it only if it has changed.
Like here: https://github.com/FriendsOfGalaxy/galaxy-integration-epic/blob/master/src/local.py#L40
or in batch like here: https://github.com/FriendsOfGalaxy/galaxy-integration-origin/blob/master/src/local_games.py#L281
This way we make it lightweight for drive and still keep a nice feature that is quick detection just after you installed a uplay game (that is desirable in case you install it though Galaxy).
@jneumaier are you still interested in making PR? What do you think about my suggestion?
@FriendsOfGalaxy I like your idea. Currently I have no time for a PR, will try to find some in the future.
The stat comparison might be done here: https://github.com/FriendsOfGalaxy/galaxy-integration-uplay/blob/41cd3115e90555cc1e43c1dcc43d9fce21a442ee/src/local_helper.py#L74-L87
Yes, we have to decide where to store previous stats. This function is used here: https://github.com/FriendsOfGalaxy/galaxy-integration-uplay/search?q=get_game_installed_status
Looks like un-spaghetting candidate..
One way to do it cleanly would be to create "file watcher" class that do only this: https://github.com/FriendsOfGalaxy/galaxy-integration-uplay/blob/41cd3115e90555cc1e43c1dcc43d9fce21a442ee/src/local_client.py#L112-L129
Other way (more functional) - gether all files stats in one step and then pipe them to another function like get_game_installed_status
.
To double check - I just wrote this without much investigation.
My drives show read access on plenty of _uplayinstall.state files all the time forever with GOG Galaxy started.
Status for all games is updated in an endless loop with a sleep time of 1 seconds between executions.
https://github.com/FriendsOfGalaxy/galaxy-integration-uplay/blob/41cd3115e90555cc1e43c1dcc43d9fce21a442ee/src/local_game_status.py#L183
In each execution the game installation and running state is updated. While the running state is retrieved with rather cheap mechanisms, the game installation status update requires disk access for each game.
I think it would be better to update the game installation status less frequently, at most one time every minute.
Maybe the GameStatus.Installed could be cached in each game object and only be updated if a boolean flag is passed to this method:
https://github.com/FriendsOfGalaxy/galaxy-integration-uplay/blob/41cd3115e90555cc1e43c1dcc43d9fce21a442ee/src/local_game_status.py#L157-L169
Not sure about the implementation but this update mechanism interval does not seem reasonable to me. I can prepare a PR if you agree to my finding.