Bullet Train on Rails: Improving web app performance w/ tools
Three Ruby-based tools for improving redis cache store performance, identifying N+1 queries, and pre-rendering simple html structures in your Ruby/Rails application
at 2017-06-23 14:13:25 -0700 ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" Processing by PostsController#index as HTML Post Load (0.2ms) SELECT "posts".* FROM "posts" Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = ? [["post_id", 1]] Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = ? [["post_id", 2]] Rendered posts/index.html.erb within layouts/application (24.2ms) Completed 200 OK in 1297ms (Views: 1283.8ms | ActiveRecord: 0.9ms) user: alyss.noland http://localhost:3000/ N+1 Query detected Post => [:comments] Add to your finder: :includes => [:comments] flyerhzm/bullet
authors.name as author_name") end SELECT posts.*, authors.name as author_name FROM "posts" INNER JOIN "authors" ON "authors"."id" = "posts"."author_id" ORDER BY "posts"."created_at" DESC Code: Resulting query:
# get a flat list of headers headers = [] html_doc.css('h1, h2, h3').each do |header| headers.push({ id: header.attribute('id').to_s, content: header.content, level: header.name[1].to_i, children: [] }) end [3,2].each do |header_level| header_to_nest = nil headers = headers.reject do |header| if header[:level] == header_level header_to_nest[:children].push header if header_to_nest true else header_to_nest = header if header[:level] == (header_level - 1) false end end end headers end Limitation: no user-specific content Faster than javascript, but hurts our TTFB