-
Notifications
You must be signed in to change notification settings - Fork 115
Dz3 #98
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?
Dz3 #98
Conversation
cyprus11
commented
Apr 3, 2023
- Разобрался с профилированием запросов в БД;
- узнал о новых гемах(activerecord_import, strong_migrations)
- сделал ДЗ
<% end %> | ||
<% end %> | ||
</ul> | ||
==================================================== |
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.
Можно использовать рендеринг коллекций, чтобы сохранить удобство паршлов и не так сильно проиграть в производительности.
Там можно даже задать шаблон разделителя: https://guides.rubyonrails.org/layouts_and_rendering.html#spacer-templates
## Проблема 1 | ||
- Большое количество рендера паршелов, общее время отрисовки - 13688 мс. Решение - перенести всё в один template | ||
|
||
Так же добавил составной индекс, правда по времени загрузка особо быстрее не стала. |
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.
Потому что время уходит не рендеринг в основном. Но индекс всё равно полезно, особенно если заходить со стороны оптимизации нагрузки на БД.
- Большое количество рендера паршелов, общее время отрисовки - 13688 мс. Решение - перенести всё в один template | ||
|
||
Так же добавил составной индекс, правда по времени загрузка особо быстрее не стала. | ||
После кэширования всей страницы, время отрисовки страницы стало 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.
Закэшировать конечно можно, но надо тогда предусмотреть сброс кэша в случае изменений в расписании или в данных автобусов и тд
@@ -40,6 +40,7 @@ | |||
t.integer "duration_minutes" | |||
t.integer "price_cents" | |||
t.integer "bus_id" | |||
t.index ["from_id", "to_id"], name: "index_trips_on_from_id_and_to_id" |
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,34 +1,52 @@ | |||
# Наивная загрузка данных из json-файла в БД | |||
# rake reload_json[fixtures/small.json] | |||
task :reload_json, [:file_name] => :environment do |_task, args| | |||
json = JSON.parse(File.read(args.file_name)) | |||
json = FastJsonparser.parse(File.read(args.file_name), symbolize_keys: false) |
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.
👍
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.
Спасибо, я кстати раньше не сталкивался с этим гемом
Service.delete_all | ||
Trip.delete_all | ||
ActiveRecord::Base.connection.execute('delete from buses_services;') | ||
[ |
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.
Код из rake-таски лучше в сервис выносить, удобнее работать с просто ruby-классом, чем с рейк-таской
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.
👍