-
Notifications
You must be signed in to change notification settings - Fork 12
optimization #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
optimization #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| --require spec_helper |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| class BusesService < ApplicationRecord | ||
| belongs_to :bus | ||
| belongs_to :service | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| <li><%= "#{service.name}" %></li> | ||
| <div class='service-item'> | ||
| <li><%= "#{service.name}" %></li> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| <li><%= "Отправление: #{trip.start_time}" %></li> | ||
| <li><%= "Прибытие: #{(Time.parse(trip.start_time) + trip.duration_minutes.minutes).strftime('%H:%M')}" %></li> | ||
| <li><%= "В пути: #{trip.duration_minutes / 60}ч. #{trip.duration_minutes % 60}мин." %></li> | ||
| <li><%= "Цена: #{trip.price_cents / 100}р. #{trip.price_cents % 100}коп." %></li> | ||
| <li><%= "Автобус: #{trip.bus.model} №#{trip.bus.number}" %></li> | ||
| <div class="trip-item"> | ||
| <li><%= "Отправление: #{trip.start_time}" %></li> | ||
| <li><%= "Прибытие: #{(Time.parse(trip.start_time) + trip.duration_minutes.minutes).strftime('%H:%M')}" %></li> | ||
| <li><%= "В пути: #{trip.duration_minutes / 60}ч. #{trip.duration_minutes % 60}мин." %></li> | ||
| <li><%= "Цена: #{trip.price_cents / 100}р. #{trip.price_cents % 100}коп." %></li> | ||
| <li><%= "Автобус: #{trip.bus.model} №#{trip.bus.number}" %></li> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| class AddIndexesToTrip < ActiveRecord::Migration[5.2] | ||
| disable_ddl_transaction! | ||
|
|
||
| def change | ||
| add_index :trips, [:from_id, :to_id], algorithm: :concurrently | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Плюс за |
||
| add_index :trips, :bus_id, algorithm: :concurrently | ||
| add_index :buses_services, :bus_id, algorithm: :concurrently | ||
| add_index :buses_services, :service_id, algorithm: :concurrently | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| require 'rails_helper' | ||
| require 'rspec-sqlimit' | ||
| require 'rake' | ||
| require 'benchmark' | ||
| load 'Rakefile' | ||
|
|
||
| RSpec.describe TripsController, type: :controller do | ||
| before do | ||
| Rake::Task['reload_json'].reenable | ||
| Rake::Task['reload_json'].invoke('fixtures/small.json') | ||
| end | ||
| let!(:trip) { Trip.preload(:from, :to).take } | ||
|
|
||
| it 'correct trips count' do | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Хорошо читается, когда получается согласованное предложение, например |
||
| get :index, params: { from: trip.from.name , to: trip.to.name } | ||
| expect(assigns(:trips).size).to eq(9) | ||
| expect(assigns(:from).name).to eq(trip.from.name) | ||
| expect(assigns(:to).name).to eq(trip.to.name) | ||
| end | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Лишний отступ |
||
|
|
||
|
|
||
| it 'run in time' do | ||
| time = Benchmark.realtime do | ||
| get :index, params: { from: trip.from.name , to: trip.to.name } | ||
| end | ||
|
|
||
| puts "Controller time: #{time}" | ||
|
|
||
| expect(time).to be < 0.006 | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| end | ||
|
|
||
| it "doesn't send unnecessary requests to db" do | ||
| expect { get :index, params: { from: trip.from.name , to: trip.to.name } }.not_to exceed_query_limit(2) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 за 'rspec-sqlimit' |
||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍