HaJaeKyung / KittyExtension

Fan add-on for https://www.cryptokitties.co
MIT License
232 stars 88 forks source link

Avoid repeated requests to cryptokitties api #4

Closed VesterDe closed 6 years ago

VesterDe commented 6 years ago

I've noticed the cryptokitties api is degrading in performance (or is it just me, in central Europe?). I doubt it's because of this addon, but still.

Perhaps the addon could store the results of past api calls in localstorage, as a service to the nice people developing cryptokitties (who probably haven't slept for a few days now). It would also improve user experience a great deal.

HaJaeKyung commented 6 years ago

I'm working on this now. How many of the past kitties do think would be a good idea to store? I think if you stored all of them that would be bad once you start getting to 20k+. I was thinking keeping the 1000 most recent.

VesterDe commented 6 years ago

Ah, didn't see your comment till I already made the pull request :) That's a good question.

localStorage is tricky because you can only save key value pairs, no objects. My solution was to JSON.stringify it, but keeping tabs on how many you have stored would mean searching through the localStorage keys for the pattern kitty-{id} and deleting it based on the cache age, I guess?

HaJaeKyung commented 6 years ago

I think I have a nice solution that has two tables. One that always stores your own kitties and one that stores the 1000 most recent.

VesterDe commented 6 years ago

That seems logical. Looking forward to seeing something, the site is less and less accessible it seems :)

HaJaeKyung commented 6 years ago

Uploaded new version please let me know how it goes. Was a little hard to test with how slow the site was.

jgoggan commented 6 years ago

Nice! Seems to be working well for me. I ran it across my 10 cats and it grabbed data for 3 of them. The others timed out due to network load. Then I reloaded the page and ran it across all 10 again -- and those 3 immediately popped up -- and the others started trying to grab data again.

So, the caching seems to work -- and really makes a difference in relieving some load. Thanks!

HaJaeKyung commented 6 years ago

Thanks. I will add a failure indicator next @jgoggan

HaJaeKyung commented 6 years ago

Looks like everything is good now 👍

bitcoinrate commented 6 years ago

How to access to API, is it document?

Thanks