Skip to content

ДЗ 3 #20

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 4 commits into
base: master
Choose a base branch
from
Open

ДЗ 3 #20

wants to merge 4 commits into from

Conversation

kortirso
Copy link

No description provided.

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.

Nice work, thanks 👍


class UploadData
def self.call(file_name)
json = JSON.parse(File.read(file_name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Грузим в память весь json, который может быть большим
Плюс можно выиграть за счёт Oj

uploaded_services = Service.all.inject({}) { |acc, elem| acc.merge!(elem.name => elem.id) }
# uploaded_services == {"Ремни безопасности"=> Service, ...}

cities = Set.new
Copy link
Collaborator

Choose a reason for hiding this comment

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

Кажется не очень хорошая идея здесь использовать Set
Так как Set позволяет хранить только уникальные объекты, ему надо постоянно сравнивать cities, которые сами по себе являются хэшами.

# save to DB
result = City.import(cities.to_a, returning: [:id, :name])
uploaded_cities = result.results.inject({}) { |acc, elem| acc.merge!(elem[1] => elem[0]) }
# uploaded_cities == {"Сочи"=>1, "Тула"=>2, "Самара"=>3, "Красноярск"=>4, "Волгоград"=>5, "Рыбинск"=>6, "Саратов"=>7, "Москва"=>8, "Ярославль"=>9, "Ростов"=>10}
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 Плюс за коммент, без него было бы сложновато понять что получается

@@ -2,15 +2,24 @@
<%= "Автобусы #{@from.name} – #{@to.name}" %>
</h1>
<h2>
<%= "В расписании #{@trips.count} рейсов" %>
<%= "В расписании #{@trips.size} рейсов" %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


## Находка 1
Раздумия над алгоритмом загрузки показали, что:
- должно быть слишком много запросов на создание/поиск городов, т.к. их всего 10, то проще и быстрее создать их за 1 прозод через файл, сформировать список загруженных и затем использовать его вместо постоянного обращения к БД
Copy link
Collaborator

Choose a reason for hiding this comment

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

Совершенно верно 👍

- при третьем проходе формируются маршруты
- результат
- medium файл стал загружаться за 7 секнуд
- large - 23 секунды
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

- время импорта large данных - 19 секунд
- рендеринг страницы
Rendered trips/index.html.erb within layouts/application (705.2ms)
Completed 200 OK in 717ms (Views: 702.6ms | ActiveRecord: 12.0ms)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 nice!

- использовалось
- [x] `bullet`
- [x] `pghero`
- здравый смысл и опыт
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


def change
add_index :trips, [:from_id, :to_id], algorithm: :concurrently
add_index :buses_services, [:bus_id, :service_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.

Плюсик за concurrently

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