Open
Conversation
spajic
approved these changes
Apr 7, 2019
Owner
spajic
left a comment
There was a problem hiding this comment.
Хорошая работа, респект за тесты!
| @@ -0,0 +1,10 @@ | |||
| class AddIndexesToTrip < ActiveRecord::Migration[5.2] | |||
| disable_ddl_transaction! | |||
| disable_ddl_transaction! | ||
|
|
||
| def change | ||
| add_index :trips, [:from_id, :to_id], algorithm: :concurrently |
| 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) |
|
|
||
| puts "Controller time: #{time}" | ||
|
|
||
| expect(time).to be < 0.006 |
| end | ||
| let!(:trip) { Trip.preload(:from, :to).take } | ||
|
|
||
| it 'correct trips count' do |
Owner
There was a problem hiding this comment.
Хорошо читается, когда получается согласованное предложение, например it 'has correct trips count'
| 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 |
| @@ -0,0 +1,44 @@ | |||
| # frozen_string_literal: true | |||
|
|
|||
| require 'rails_helper' | |||
Owner
There was a problem hiding this comment.
requireы было бы лучше вынести в rails_helper и реквайрить уже его
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Проблема импорта данных
импорт из файла
large.jsonбыл не возможен т.е. занимал огромное количество временидля feedback loop был выбран файл
small.json, который исполнялся 7.5 сек.Анализ логов выявил, что операции insert быстрые, но их слишком много.
Для вставки batches, использовал gem
activerecord-import, позволяющий вставлять пачками, используя при это active record валидации, время уменьшилось до 3 сек, но еще оставлось много запросов к базе типаfind_by_name, для уменшения кол-ва запросов, было принято решение кешировать объекты в памяти, что позволило скротить время до 0.5 сек.Файл
large.jsonстал загружаться за приемлемое - 30 сек времяПроблема отображения расписаний
После загрузки
large.jsonв базу, оказалось что страницаавтобусы/Самара/Москвазагружается очень долго, результат загрузки(для тестирования использовалk6)Было выявлено 2 основные проблемы:
tripsвызывалисьbusиservices, добавленeager_loadРезультат:
Доп оптимзации:
Кешировние partial
_serviceУдаление partial
_delimetr