-
Notifications
You must be signed in to change notification settings - Fork 115
ДЗ 3 #20
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?
ДЗ 3 #20
Conversation
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.
Nice work, thanks 👍
|
||
class UploadData | ||
def self.call(file_name) | ||
json = JSON.parse(File.read(file_name)) |
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.
Грузим в память весь json
, который может быть большим
Плюс можно выиграть за счёт Oj
uploaded_services = Service.all.inject({}) { |acc, elem| acc.merge!(elem.name => elem.id) } | ||
# uploaded_services == {"Ремни безопасности"=> Service, ...} | ||
|
||
cities = Set.new |
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.
Кажется не очень хорошая идея здесь использовать Set
Так как Set
позволяет хранить только уникальные объекты, ему надо постоянно сравнивать cities
, которые сами по себе являются хэшами.
# save to DB | ||
result = City.import(cities.to_a, returning: [:id, :name]) | ||
uploaded_cities = result.results.inject({}) { |acc, elem| acc.merge!(elem[1] => elem[0]) } | ||
# uploaded_cities == {"Сочи"=>1, "Тула"=>2, "Самара"=>3, "Красноярск"=>4, "Волгоград"=>5, "Рыбинск"=>6, "Саратов"=>7, "Москва"=>8, "Ярославль"=>9, "Ростов"=>10} |
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.
👍 Плюс за коммент, без него было бы сложновато понять что получается
@@ -2,15 +2,24 @@ | |||
<%= "Автобусы #{@from.name} – #{@to.name}" %> | |||
</h1> | |||
<h2> | |||
<%= "В расписании #{@trips.count} рейсов" %> | |||
<%= "В расписании #{@trips.size} рейсов" %> |
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.
👍
|
||
## Находка 1 | ||
Раздумия над алгоритмом загрузки показали, что: | ||
- должно быть слишком много запросов на создание/поиск городов, т.к. их всего 10, то проще и быстрее создать их за 1 прозод через файл, сформировать список загруженных и затем использовать его вместо постоянного обращения к БД |
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.
Совершенно верно 👍
- при третьем проходе формируются маршруты | ||
- результат | ||
- medium файл стал загружаться за 7 секнуд | ||
- large - 23 секунды |
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.
👍
- время импорта large данных - 19 секунд | ||
- рендеринг страницы | ||
Rendered trips/index.html.erb within layouts/application (705.2ms) | ||
Completed 200 OK in 717ms (Views: 702.6ms | ActiveRecord: 12.0ms) |
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.
👍 nice!
- использовалось | ||
- [x] `bullet` | ||
- [x] `pghero` | ||
- здравый смысл и опыт |
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.
👍
|
||
def change | ||
add_index :trips, [:from_id, :to_id], algorithm: :concurrently | ||
add_index :buses_services, [:bus_id, :service_id], algorithm: :concurrently |
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.
Плюсик за concurrently
No description provided.