-
Notifications
You must be signed in to change notification settings - Fork 115
Week3 data base optimization #115
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?
Week3 data base optimization #115
Conversation
usernaimandrey
commented
Feb 12, 2025
- Потоковая згрузка данных
- Оптимизация загрузки страници
lib/profiler.rb
Outdated
send(reporter_type) | ||
end | ||
|
||
def memeory_prof |
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.
Опечатка
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.
Спасибо
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.
respect за то что справились с импортом огромного файла и в целом, но вы упустили момент с оптимизацей partials, которые сделаны у меня намеренно ужасно
@from = City.find_by!(name: params[:from]) | ||
@to = City.find_by!(name: params[:to]) | ||
trips = Trip | ||
.eager_load(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.
👍
Перед оптимизацией программа затрачивает на обработку файла в 50000 строк 335 MB | ||
|
||
## Гарантия корректности работы оптимизированной программы | ||
1. На писан юнит тест гарантирующий корректную работу рейк таски `UtilsTest` |
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. На писан юнит тест гарантирующий корректную работу рейк таски `UtilsTest` | ||
2. Написан системный тест который гарантирует сохранность структуры страници `TripsTest` |
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.
👍👍
|
||
|
||
|
||
## Результаты |
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.
результаты отличные
но с пагиганцией вы упустили тему с оптимизацией partials как я понял - там в моей версии сделано очень плохо, хорошо бы это поправить тоже
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.
Попробовал сделать через collection
в целом работает довольно шустро без пагинации
|
||
## Защита от регрессии производительности | ||
1. Перформ тест проверющий что таска выполняется не более 60 сек | ||
2. Тест контроллера - если будет n + 1 запрос тест упадет с ошибкой |
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.application.routes.draw do | ||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
get "/" => "statistics#index" | ||
get "автобусы/:from/:to" => "trips#index" | ||
mount PgHero::Engine, at: "pghero" |
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.
pghero = one love тоже
@@ -1,3 +1,5 @@ | |||
# frozen_string_literal: 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.
я понимаю что это рубокоп, но лучше было бы это не комитить :harold:
disable_ddl_transaction! | ||
|
||
def change | ||
add_index :trips, :from_id, algorithm: :concurrently |
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.
возможно лучше составной индекс [from_id, to_id], потому что поиск постоянно идёт именно по направлению
BUSES_COMMAND = "copy buses (id, number, model) from stdin with csv delimiter ';'" | ||
BUSES_SERVICES_COMMAND = "copy buses_services (bus_id, service_id) from stdin with csv delimiter ';'" | ||
|
||
@@city_by_name = {} |
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.
в книге Polished Ruby недавно прочитал рекомендацию никогда не использовать @@, с ним возможны неприятные приколы
в целом книга от легенды - Jeremy Evans, так что стоит ознакомиться
|
||
Service.import @@services.values | ||
|
||
ActiveRecord::Base.connection.raw_connection.copy_data TRIPS_COMMAND do |
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.
лайк за copy_data
@@ -0,0 +1,47 @@ | |||
include make-compose.mk |
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.
У тебя такие файлы как то генерируются или ты вручную делаешь? Или есть какой то шаблон который ты копируешь? Мне лень такое делать, но это так то очень удобно, особенно в команде
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.
Нет сам делаю)
Мне лень такое делать, но это так то очень удобно
Мне вот лень каждый раз перед вводом команды вспоминать как там она пишется) а тут коротко и ясно make ...
Вообще make это довольно древняя тулза, ее еще использовали для сборки C программ
https://ru.hexlet.io/blog/posts/makefile-as-task-runner
Как альтернатива еще можно гем dip использовать, но он только для контейнерных приложух, а make можно под любое адаптировать
https://github.com/bibendi/dip