Skip to content

Conversation

@peresvetjke
Copy link

No description provided.

City.insert_all(cities_names.map { |name| { name: name } })
```

Готово! большой файл загружается за 4 секунд:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 секунд

Comment on lines +1 to +3
def insert_multiple(array)

end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

место для helper'a, который так и не появился, чтобы переиспользовать конструкцию с INSERT_INTO

Copy link
Collaborator

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`.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в последствии отключаем

Copy link
Collaborator

@spajic spajic left a 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

<% end %>
</ul>
<%= render "delimiter" %>
====================================================
Copy link
Collaborator

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
Copy link
Collaborator

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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pg_hero может это подсказать, многие ребята в этом ДЗ добавляют индексы чисто по совету pg_hero

Comment on lines +1 to +3
def insert_multiple(array)

end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Сейчас конечно уже лучше использовать Rails 6+ для batch-impoert. Я обновлю рельсу в этом задании

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants