chamchenko / plugin.video.nbainternational

NBA Add-On for Kodi
GNU General Public License v2.0
8 stars 6 forks source link

Live games list doesn't refresh #15

Closed nre-ableton closed 2 years ago

nre-ableton commented 2 years ago

I use this plugin with Kodi on a dedicated Raspberry Pi server that is attached to our TV, and is rarely rebooted or shut down. The plugin doesn't ever refresh the list of live games, though, so whatever I see in that menu is from the last time I watched a live game some days ago. Disabling/enabling the plugin doesn't seem to cause a refresh; the only way to fix this is to restart Kodi (which for me means a reboot).

chamchenko commented 2 years ago

Hi @nre-ableton The add-on uses caching to minimise loading time, instead of restarting Kodi/system you can just open an other add-on then go back to the NBA add-on and all the pages / games will be reloaded without using cache.

nre-ableton commented 2 years ago

@chamchenko Makes sense, the caching is definitely a useful feature. However, I am not sure that it makes sense to cache the list of live games, since it is expected that they will change.

What would you think about this patch?

 def BROWSE_GAMES_MENU(plugin):
     FAVORITE_TEAMS = get_profile_info()['FAVORITE_TEAMS']
     yield Listitem.from_dict(
                                 BROWSE_GAMES,
-                                bold('Live Games')
+                                bold('Live Games'),
+                                params = {'DATE': None}
                             )

Also, when one is watching games that are ongoing, this means that the information about which games are live and which ones have finished would be accurate.

I've not looked at the code for this plugin much, so I am not sure if there is a better way to implement this. However, if you're not opposed to the above solution, I'd be happy to submit a PR.

chamchenko commented 2 years ago

@nre-ableton It could really be useful to have accurate information I agree. I haven't really thought about it because I was mainly trying to get something working for the playoffs last year and till today I still consider this as a Beta. I'm surely open to any suggestion that would make this add-on better, so if you have tested the patch and it's doing that without issues then yes I would implement it. Edit: If you have time to test maybe the solution 2 in willforde answer here could be a better way to implement it.

nre-ableton commented 2 years ago

@chamchenko I have definitely not tested anything, I only spent about 2 minutes looking around the plugin's source code when writing my comment above. :laughing: Anyways, when I have some spare time, I'll take a look at the link you've sent, do some proper testing, and submit a PR.

nre-ableton commented 2 years ago

@chamchenko Ok, I had some time today to sit down and properly debug the problem. It's actually not really a caching problem; it's caused by the fact that the DATE variable in BROWSE_GAMES is calculated once and never refreshed, but for live games we always want this value to be the current date. So my patch suggestion above is wrong, it should be:

 def BROWSE_GAMES_MENU(plugin):
     FAVORITE_TEAMS = get_profile_info()['FAVORITE_TEAMS']
     yield Listitem.from_dict(
                                 BROWSE_GAMES,
-                                bold('Live Games')
+                                bold('Live Games'),
+                                params = {'DATE': nowWEST()}
                             )

I submitted a PR to fix this: #17.

While I was looking into this issue, I also discovered some other caching-related stuff that could be improved (see https://github.com/chamchenko/plugin.video.nbainternational/pull/17/commits/41b79476b4a4b1ed5c7194eef4ada5addbdcaac2). I had a look at the solution you suggested here, but I don't think it makes sense to add the cache_ttl decorator to BROWSE_GAMES. Adding cache_ttl would apply to all queries, not just those for live games. By using urlquick's cache, there is a bit more flexibility. I don't think that we want to cache the view itself, as that should be pretty quick to construct.

Anyways, let's continue this discussion in #17.