-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show previous WCA stats on nametags #52
Comments
I'm leaning towards doing it only once and caching it and then maybe have a "expire cache" button somewhere (or cronjob) in case it needs to be refetched (people went to more competitions after registering). |
Regarding the caching: You can add caching directly onto Faraday and it'll work like a browser. It would be just a matter of adding expires headers to the API itself. These could be set to at least one day since the WCA export only gets updated weekly. So, performance-wise we would be covered using that solution (speaking of performance: Rust is freaking fast, it renders 35,000 competitors in 60ms (http://178.62.217.148/competitors?q=20), the single endpoint for a competitor (http://178.62.217.148/competitors/2007WEIN01) takes less than 1ms). This wouldn't help if the API goes down for a long period of time though. The cache would be considered stale, but there would be no data to be fetched. How would you cache the parsed responses? As attributes on the competitors table? What I currently have in mind is a read-through cache like so: class WCACache
def initialize(gateway, cache)
@gateway = gateway
# this could be redis, a file store or MySQL.
# It should be able to handle arbitrary data structures though. Maybe using Marshal?
@cache = cache
end
def psych_sheet(puzzle_id, competitor_ids)
result = @gateway.psych_sheet(puzzle_id, competitor_ids)
@cache.set("psych-sheet-#{puzzle_id}-#{competitor_ids}", result)
result
rescue WCAGateway::ConnectionError
@cache.get("psych-sheet-#{puzzle_id}-#{competitor_ids}") || []
end
end We would always fetch the most recent results unless the API is down in which case we'd return data from the cache. The cache key would need some work though. As it's currently implemented each new registration will invalidate the entire cache. |
I'm not so much concerned about response time but more about network latency... unless I would host the rust thing on the same server of course. |
The old software had this feature for nametags. Would be fancy to have the same here (nametags already exist, just not the WCA stats in the bottom line).
Again the question: Should we do this once and then cache it or do it in a batch every time the nametags page is rendered?
@timhabermaas
The text was updated successfully, but these errors were encountered: