Skip to content

Conversation

@bshourse
Copy link

@bshourse bshourse commented Mar 6, 2025

Задание #3

  • Оптимизировал rake таску

  • Оптимизировал запросы при загрузки вьюхи: trips/index.html.erb

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.

Спасибо за работу! ✅

<% 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.

https://guides.rubyonrails.org/layouts_and_rendering.html#spacer-templates

можно использовать рендеринг коллекций и даже там задать delimiter параметром

так можно и сохранить удобство паршлов и не так сильно проиграть в производительности

1. Выполняется 30% от общего времени

```ruby
SELECT COUNT(*) FROM "trips" WHERE "trips"."from_id" = $1 AND "trips"."to_id" = $2
Copy link
Collaborator

Choose a reason for hiding this comment

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

count по итогу нам вообще не нужен, тк мы грузим все данные и можем просто взять size

```

**Решение**
Добавил композитный индекс по двум полям
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

```
Sort (cost=953.40..955.84 rows=977 width=34)
Sort Key: start_time
-> Bitmap Heap Scan on trips (cost=14.31..904.88 rows=977 width=34)
Copy link
Collaborator

Choose a reason for hiding this comment

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

лайк за explain

```

Скорость закрузки страницы снизилась от 144ms до 290 ms
Думаю на большом объеме данных результат будет более наглядным
Copy link
Collaborator

Choose a reason for hiding this comment

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

да, вообще тут на время рендеринга страницы эти запросы не так уж влияют на фоне паршлов

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


Скорость загрузки стариницы осталась примерно на том же уровне иногда опускаясь до 129 ms
Хотя PGHero показывает по прежнему 37% от общего времени выполнение запроса на получение сервисов, решил остановиться.
В бюджет почти уложился(хотел до 0.1 сек)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

subject(:make_request) { visit(trips_path(from: 'Самара', to: 'Москва'))}

before(:all) do
system 'RAILS_ENV=test bin/rake utils:reload_json[fixtures/large.json]'
Copy link
Collaborator

Choose a reason for hiding this comment

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

удобнее было бы работать, вынеся контент из рейк-таски в рубишный класс

it 'displays trip details', :aggregate_failures do
make_request
expect(page).to have_content('Автобусы Самара – Москва')
expect(page).to have_content('В расписании 1004 рейсов')
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

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