Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Dz3 #98

wants to merge 2 commits into from

Conversation

cyprus11
Copy link

@cyprus11 cyprus11 commented Apr 3, 2023

  • Разобрался с профилированием запросов в БД;
  • узнал о новых гемах(activerecord_import, strong_migrations)
  • сделал ДЗ

<% end %>
<% end %>
</ul>
====================================================
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

## Проблема 1
- Большое количество рендера паршелов, общее время отрисовки - 13688 мс. Решение - перенести всё в один template

Так же добавил составной индекс, правда по времени загрузка особо быстрее не стала.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Потому что время уходит не рендеринг в основном. Но индекс всё равно полезно, особенно если заходить со стороны оптимизации нагрузки на БД.

- Большое количество рендера паршелов, общее время отрисовки - 13688 мс. Решение - перенести всё в один template

Так же добавил составной индекс, правда по времени загрузка особо быстрее не стала.
После кэширования всей страницы, время отрисовки страницы стало 23 мс.
Copy link
Collaborator

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

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

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

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;')
[
Copy link
Collaborator

Choose a reason for hiding this comment

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

Код из rake-таски лучше в сервис выносить, удобнее работать с просто ruby-классом, чем с рейк-таской

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.

👍

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