Conversation
…on code for API using basic auth
…he back-end, Added admin check, Render json for adopted drains
|
@jafowler49 👍 this looks good. I'm a little concerned about how it will fare as the number of adopted drains grows though. Would you be able to test this with, say, 10000 adopted drains (noting that the Heroku request timeout is 60s)? We may need to introduce pagination of the responses. |
|
oh ok, sounds like scalability/response times might be an issue. good call I will test it out |
| before_action :authenticate | ||
|
|
||
| def index | ||
| @things = Thing.where.not(user_id: !nil) |
There was a problem hiding this comment.
I don't think you want !nil, but just nil
Interestingly -- not that anyone cares -- !nil evaluates to true and true gets converted to 1 in the sql, so you end up with WHERE user_id != 1. (I only know this because I checked the console)
…s. I created this initially to test out how the API would handle load
|
hey @jszwedko , sorry this took so long... anyways added some work on this. hoping you can check it and see what you think. thanks |
jszwedko
left a comment
There was a problem hiding this comment.
Thanks @jafowler49 !
Overall, this is is shaping up well, but I'm still a little concerned about the CSV API route returning all of the records rather than paginating like the other formats. I realize it is difficult to encode the pagination information directly in the response body, but we can leverage HTTP response headers to indicate the paging information. I also think we could opt to just serve JSON for now since that is the most common API format these days and drop XML and CSV.
Could we also configure the max_per_page to be 1000 and drop the default to 100? Or whatever makes sense with your testing; I just want to make sure we have a maximum.
Gemfile
Outdated
| group :development do | ||
| gem 'byebug' | ||
| gem 'spring' | ||
| gem 'kaminari' |
There was a problem hiding this comment.
We'll need this gem in production too, no? It feels like it should be at the top level. Do you mind locking it to a major version as well (I locked the rest in #259) so that it is easier to update without breaking compatibility.
There was a problem hiding this comment.
~>1.0 includes supported versions. the older version dropped support for an earlier version of Ruby
Gemfile
Outdated
|
|
||
| gem 'dotenv-rails', groups: [:development, :test] | ||
| gem 'rails', '~> 4.2.4' | ||
| gem 'faker', '1.7.3' |
There was a problem hiding this comment.
Do we need an exact version here?
There was a problem hiding this comment.
Changed that to have the version ~> 1.7.0... These are the sure compatible versions, not sure if they will change support in the future.
| # enable it only for database authentication. The supported strategies are: | ||
| # :database = Support basic authentication with authentication key + password | ||
| # config.http_authenticatable = false | ||
| config.http_authenticatable = false |
There was a problem hiding this comment.
Never mind, I see that the API is locked to authenticated users.
| root to: 'main#index' | ||
|
|
||
| # API | ||
| scope '/api' do |
db/seeds.rb
Outdated
|
|
||
| r = Random.new | ||
|
|
||
| =begin |
There was a problem hiding this comment.
Did you mean to leave this commented?
lib/tasks/data.rake
Outdated
| unless Rails.env.production? | ||
| Thing.first(10_000).each do |t| | ||
| if t.user_id.blank? | ||
| t.user_id = User.find_by('id' => Random.rand(1..User.last.id)).id |
There was a problem hiding this comment.
I think something like User.order('RANDOM()').limit(1) is more idiomatic here. Could we maybe print out an error message if the user attempts to run this in production?
|
|
||
| # Determine if the user supplied a valid page number, if not they get first page | ||
| def make_cur_page | ||
| page = params[:page].blank? ? 2 : params[:page] |
| @@ -0,0 +1,44 @@ | |||
| require 'test_helper' | |||
|
|
|||
| class AdoptedControllerTest < ActionController::TestCase | |||
There was a problem hiding this comment.
I like checking the content-type, but could we make a few assertions on the response content to make sure the right records are returned? It'd also be nice to exercise the paging logic a little here.
… had to change it on my local env)
|
Hi @jszwedko Finally worked on this. Sorry for all the commits, I merged Prod in to my local branch. Last 1 was fixing merge conflicts and Rubocop requests, next 10 were actual changes, and the rest were just commits from Prod. Let me know what further changes I should make to the API. I added basic tests. Is there an easy way to test 1000 or so items within a Test Case? Hope this helps Also, since I left the City I've been working on my iOS and UI skills. So if you guys need an iOS app for Adopt a Drain, I'm your guy. Best! |
This should be ready for initial review
Thanks!