I was looking at the network traffic of the ‘last battle viewer’ of Coders of the caribbean.
I noticed there is a post to https://www.codingame.com/services/gamesPlayersRankingRemoteService/findLastBattlesAndProgressByAgentId which seems to download (post / download, http verbs thank you ) ~20k to get the same battle data (same gameId) every 3 or 4 seconds
I checked and the content is the same.
I think you can optimize the code to only do 1 post as the battle are long finished.
I think it will be cheaper for our bandwidth/data plan as yours
POST request isn’t a download (on the contrary, it’s typically used to upload data to the server).
in this particular case they use it to send agent id and last request time to get new results.
Strictly speaking, a GET here would be the more RESTful choice, I’m guessing they’re using POST to keep uri tidy.
As for why they’re doing it every 3-4 seconds - it’s pretty much unavoidable if you want to keep your page up to date without refreshing. I’m sure people appreciate having things like battle progress and last battles tab update in real time - that’s how it’s done under the hood, asking the server for anything new over and over.
I totally agree with you on the RestFul part as, even though it’s not forbidden by http standard, POST can be abused to download things (see elasticsearch _search for example)
Plus, using GET can benefit from browser cache. I’m not sure about POST
For the other part, I don’t agree with you. The contest is over, there is no battle pending, the post always request the same gameId and respond with the same data.
So I don’t understand why. I think it’s a miss on CG part that can save them (and us, but mainly them) Megas of data transfer.
Next, I’m sure there is another (optimized) way to get the last battle info than to request the full battle each time.
Thanks nmahoude for reporting the possible optimization, we filed a trello card about this. Not so sure so many of you keep the last battles panel open after the contest though.
And no, we are not Restful. we use POST for calling all our services and that’s the way we like it.