-
Notifications
You must be signed in to change notification settings - Fork 114
Better db #104
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?
Better db #104
Conversation
| City.insert_all(cities_names.map { |name| { name: name } }) | ||
| ``` | ||
|
|
||
| Готово! большой файл загружается за 4 секунд: |
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.
5 секунд
| def insert_multiple(array) | ||
|
|
||
| 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.
место для helper'a, который так и не появился, чтобы переиспользовать конструкцию с INSERT_INTO
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.
Сейчас конечно уже лучше использовать Rails 6+ для batch-impoert. Я обновлю рельсу в этом задании
| ``` | ||
|
|
||
| Учитывая большое кол-во данных, кажется, нам не обойтись без кэширования `partials`. | ||
| Добавили `cache` в темплейты, включили `rails dev:cache`. |
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.
в последствии отключаем
spajic
left a comment
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!
| @from = City.find_by_name!(params[:from]) | ||
| @to = City.find_by_name!(params[:to]) | ||
| @trips = Trip.where(from: @from, to: @to).order(:start_time) | ||
| @trips = Trip.where(from: @from, to: @to).order(:start_time).preload(bus: :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.
👍
| <% end %> | ||
| </ul> | ||
| <%= render "delimiter" %> | ||
| ==================================================== |
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.
Можно не очень сильно проиграть по перформансу и сохранить удобство паршлов если юзать рендеринг коллекций. Там даже можно параметром задать шаблон spacer/delimiter: https://guides.rubyonrails.org/v7.0/action_view_overview.html#spacer-templates
| До сих пор мы (помимо `preload` и `any?`) занимались улучшением загрузки `partials`. | ||
| Что кажется верным, т.к. бд не видится боттлнеком в данном примере. Но все же добавим индексы: | ||
| ``` | ||
| add_index :cities, :name, unique: true |
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 приоритетом
| ``` | ||
| add_index :cities, :name, unique: true | ||
| add_index :buses_services, :bus_id | ||
| add_index :trips, [:from_id, :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.
pg_hero может это подсказать, многие ребята в этом ДЗ добавляют индексы чисто по совету pg_hero
| def insert_multiple(array) | ||
|
|
||
| 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.
Сейчас конечно уже лучше использовать Rails 6+ для batch-impoert. Я обновлю рельсу в этом задании
No description provided.