UEWBot / dipvis

Django-based visualiser for tournaments for the boardgame Diplomacy
GNU General Public License v3.0
7 stars 5 forks source link

Player.save() is inefficient #243

Closed UEWBot closed 1 year ago

UEWBot commented 1 year ago

Because it always reads from the WDD if wdd_player_id is set, which is very slow. This probably only needs to be done if the value has changed (or the name wasn't previously cached).

UEWBot commented 1 year ago

Player.save() also always calls add_player_bg(), which will again read the WDD. Surely that should only be done if the wdd_player_id has changed, in which case we should also be deleting any old background?

I wonder if the cache of the WDD name in Player.save() is actually worthwhile. We could just update the cache whenever we have to read the WDD anyway. I guess that's maybe because we display the WDD name on the index page, so we're displaying 20 at a time?

We do update the player background whenever we create a TournamentPlayer, and there's now a button to trigger it manually. I guess that once upon a time TDs would add Players and TournamentPlayers, then set the wdd_player_id and still wouldn't see the background. These days in that scenario they can just trigger the update. But these days Player has more attributes and gets updated more frequently (e.g. for location or backstabbr username), so that background update hurts more.