Welcome to Score (or Point) Board App! Things would be great if things weren't so slow.
We have a pre-built Rails application with two models: User
and Point
. After seeding the database with data, you'll have 100,000 rows in the users
table and 1,500,000 rows in the points
table. The index page is sl-o-o-ow and it's your job to speed it up without using any fancy technologies like memcache, redis, or Rails' fragment caching.
Clone this repository, checkout a feature branch, then get the application running as follows:
$ bundle install
$ rake db:setup
The rake db:setup
command could take a few minutes. Once it's done run rails server
and visit http://localhost:3000.
We use a gem called activerecord-import to mass import data into the database. Here is an issue to be aware of: this issue
It should take a few seconds to load. If you look at the last line of your server logs, you'll see it telling you how much time was spent rendering the views versus how much time was executing ActiveRecord
methods. Where's the bottleneck?
Your goal is to get the index page to load in under 200ms. Yes, that's milliseconds. You're permitted to do the following:
- Add new fields to the
users
andpoints
tables - Add new indexes to the
users
andpoints
tables - Add new class or instance methods to the
User
orPoint
models
The test suite should remain green. If you add any new public methods make sure you add appropriate corresponding tests.
You should write a custom rake tasks to handle populating new database tables.
You should not change the controller or view code.
Submit your solution as a pull request.
Let's add pagination to our application so we can page through all 100,000 users quickly.
Pagination is a common feature so it's worth knowing how it works.
Before you build the UI, make it so you can visit a URL like http://localhost:3000?page=3 and have it do the correct thing. You're free to change the number of users displayed per page. Read the ActiveRecord documentation on limit and offset, which will be necessary to get pagination behavior.
Add a method User.page
that works as follows:
User.by_total_points.page(3) # returns the 3rd page of users, sorted by score
Write tests for this method and implement it. If the input is nil
it should return the first page of users.
Because we're already using Twitter Bootstrap, add pagination links to the bottom of the index page using Bootstrap's pagination component. Make sure the user experience is correct. This means:
- It should display the correct number of pages
- The correct page should be marked as active
- If a user is on the first or last page, the previous or next links should be disabled (respectively)
TDD this feature using capybara.
Submit your solution as a pull request.