Skip to content
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

Closed
fw42 opened this issue Dec 5, 2014 · 3 comments · Fixed by #180
Closed

Show previous WCA stats on nametags #52

fw42 opened this issue Dec 5, 2014 · 3 comments · Fixed by #180

Comments

@fw42
Copy link
Owner

fw42 commented Dec 5, 2014

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).

screen shot 2014-12-05 at 6 17 24 pm

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

@fw42 fw42 added the WCA API label Dec 5, 2014
@fw42 fw42 added this to the Feature equivalence to old app milestone Dec 5, 2014
@fw42
Copy link
Owner Author

fw42 commented Dec 5, 2014

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).

@timhabermaas
Copy link
Collaborator

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.

@fw42
Copy link
Owner Author

fw42 commented Dec 6, 2014

Rust is freaking fast

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants