Skip to content

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

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

Conversation

usernaimandrey
Copy link

  1. Потоковая згрузка данных
  2. Оптимизация загрузки страници

lib/profiler.rb Outdated
send(reporter_type)
end

def memeory_prof

Choose a reason for hiding this comment

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

Опечатка

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.

respect за то что справились с импортом огромного файла и в целом, но вы упустили момент с оптимизацей partials, которые сделаны у меня намеренно ужасно

@from = City.find_by!(name: params[:from])
@to = City.find_by!(name: params[:to])
trips = Trip
.eager_load(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.

👍

Перед оптимизацией программа затрачивает на обработку файла в 50000 строк 335 MB

## Гарантия корректности работы оптимизированной программы
1. На писан юнит тест гарантирующий корректную работу рейк таски `UtilsTest`
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 👍


## Гарантия корректности работы оптимизированной программы
1. На писан юнит тест гарантирующий корректную работу рейк таски `UtilsTest`
2. Написан системный тест который гарантирует сохранность структуры страници `TripsTest`
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.

результаты отличные

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

Copy link
Author

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 запрос тест упадет с ошибкой
Copy link
Collaborator

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

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

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

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 = {}
Copy link
Collaborator

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

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

Choose a reason for hiding this comment

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

У тебя такие файлы как то генерируются или ты вручную делаешь? Или есть какой то шаблон который ты копируешь? Мне лень такое делать, но это так то очень удобно, особенно в команде

Copy link
Author

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

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.

3 participants