This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BikesReport::ActiveRecordSqlApproach | |
def to_a | |
Rental.joins(:bike) | |
.select(query) | |
.group('bikes.id') | |
.order('times_rented DESC') | |
.as_json(except: :id) | |
.map { |r| r.symbolize_keys!.merge!(model: MODELS.fetch(r[:model])) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Benchmark.bm { |x| x.report { BikesReport::NaiveApproach.new.to_a } } | |
# user system total real | |
# 9.670000 0.650000 10.320000 ( 10.540757) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BikesReport::NaiveApproach | |
def to_a | |
rentals.group_by { |r| r.bike_id }.reduce([]) do |result, (id, rentals)| | |
rental = rentals.first | |
result << { | |
name: rental.bike.name, | |
model: rental.bike.model, | |
times_rented: rentals.count, | |
revenue: rental.bike.price * total_interval(rentals) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
shared_examples 'a bikes report approach' do | |
subject(:approach) { described_class.new } | |
describe '#to_a' do | |
let(:cheap_bike) { create(:bike, price: 3.14) } | |
let(:expensive_bike) { create(:bike, price: 210) } | |
let!(:cheap_rentals) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Set vim-specific functions available, breaking compatibility with vi | |
set nocompatible | |
" Line Number | |
set number | |
" Syntax highlighting options | |
syntax on | |
set t_Co=256 | |
" Search Options | |
set incsearch | |
set hlsearch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
# lazy commit | |
friday-night = !git commit -am 'Finish stuff' && git push origin `git symbolic-ref --short -q HEAD` | |
# delete merged branches | |
delete-merged = !git branch --merged | grep -v \* | xargs git branch -d |
NewerOlder