Skip to content

Instantly share code, notes, and snippets.

View andrewreid's full-sized avatar

Andrew Reid andrewreid

View GitHub Profile

Keybase proof

I hereby claim:

  • I am andrewreid on github.
  • I am ndrewreid (https://keybase.io/ndrewreid) on keybase.
  • I have a public key ASC0rWlvCxSzX6Z7Uq30N4bI2O16wUQdcS4n0cWGHbLg5Ao

To claim this, I am signing this object:

@andrewreid
andrewreid / api_controller.rb
Last active December 16, 2015 09:19
Refactored API using custom SQL query
# Original method: renders take up to 300ms, a stacktonne of N+1 queries
# GET /api/users_with_qualifications/ALS.json
def users_with_qualifications
last_modified = User.with_qualifications(params[:qualification]).select("MAX(users.updated_at) as max").first.max
render(:json => []) and return if last_modified.nil?
if stale?(:last_modified => Time.parse(last_modified), :etag => params[:qualification])
# TODO: find a way to have with_highest_qualifaction(...)
qual = User::QUAL_LEVELS[params[:qualification]]
users = User.with_qualifications(params[:qualification]).select("id, first_name, last_name, qualifications_mask").order('last_name ASC').all.reject do |r|
@andrewreid
andrewreid / gist:3424581
Created August 22, 2012 11:18
Table definitions
Table "public.events"
Column | Type | Modifiers
---------------------+-----------------------------+-----------------------------------------------------
id | integer | not null default nextval('events_id_seq'::regclass)
name | character varying(255) |
location | text |
notes | text |
created_at | timestamp without time zone | not null
updated_at | timestamp without time zone | not null
default_shift_start | timestamp without time zone |