Skip to content

Conversation

@God1-ike
Copy link

No description provided.

Roman Salikov added 2 commits February 16, 2025 10:45
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.

👍

gem 'bootsnap'
gem 'rack-mini-profiler'
gem 'activerecord-import'
gem 'pghero'
Copy link
Collaborator

Choose a reason for hiding this comment

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

<3

<%= render "delimiter" %>
<% end %>

<%= render partial: "trip", collection: @trips %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 👍

<% if trip.bus.services.present? %>
<li>Сервисы в автобусе:</li>
<ul>
<%= render partial: "service", collection: trip.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.

👍

<%= render "services", services: trip.bus.services %>
<% 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.

кажется делимитер потерялся

его тоже можно параметров в render collection задать, https://guides.rubyonrails.org/layouts_and_rendering.html#spacer-templates



### Ваша находка
- запустил импорт exmaple.json файла и начал смотреть логи
Copy link
Collaborator

Choose a reason for hiding this comment

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

как говорит Nate Berkopec, если бы все смотрели логи, у меня бы не было работы

+ так же пришлось для удобсва создать можель на связь BusesService
+ все объекты сохранял сразу в переменную и hash
```
to = cities[trip['to']] ||= City.new(name: trip['to'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

## Результаты
- В результате проделанной оптимизации наконец удалось обработать файл с данными и уложиться в поставленные нами метрики.
- Удалось улучшить отрисовку страницы расписаний с 11.3с до 0.3с.
Copy link
Collaborator

Choose a reason for hiding this comment

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

0,3 или 3?

SELECT "trips".* FROM "trips" WHERE "trips"."from_id" = $1 AND "trips"."to_id" = $2 ORDER BY "trips"."start_time" ASC;
```
2) добавил индекс на фильтруемые данные сразу отсортированные
`add_index :trips, %i[from_id to_id start_time], order: {start_time: :asc}, algorithm: :concurrently`
Copy link
Collaborator

Choose a reason for hiding this comment

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

я бы start_time не стал в этот составной индекс добавлять

[from_id, to_id] можно, а start_time лучше отдельно

```
но так же прибавил в памяти, для нас пока не влияет но надо учитывать index_trips_on_from_id_and_to_id_and_start_time 2.19 MB.
Выйгрыш по скорости не такой большой
Copy link
Collaborator

Choose a reason for hiding this comment

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

в данном случае маленькая изначально доля уходит на выполнение этого SQL-запроса, поэтому выигрыша большого не может быть

но если бы мы заходили с точки зрения оптимизации БД, то там бы это очень помогло

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