Skip to content
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

Домашнее задание №3 (Лисичкин Дмитрий) #99

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
208b9eb
Add tools
Tab10id Mar 21, 2023
bf737ab
Extract rake task to separate class for simplify optimisations
Tab10id Mar 21, 2023
2758b67
Prepare code for analyze
Tab10id Mar 30, 2023
438b5ce
Add activerecord-import
Tab10id Mar 30, 2023
1bd2f31
initial case-study
Tab10id Mar 30, 2023
eda8811
Add basic test
Tab10id Mar 30, 2023
f069564
Add script for performance analyse only after tests run
Tab10id Apr 1, 2023
60b0a15
Add first measure results
Tab10id Apr 1, 2023
a1117aa
Extract model creation to separate methods
Tab10id Apr 1, 2023
4534a50
Remove unnecessary updates for bus creation
Tab10id Apr 1, 2023
d86dde7
Import bus services
Tab10id Apr 1, 2023
5366053
Remove unnecessary service find in db
Tab10id Apr 1, 2023
21547a5
Import trips
Tab10id Apr 1, 2023
a05f483
Remove unnecessary city find in db
Tab10id Apr 1, 2023
add9e9b
Add first analyze of TripsController work
Tab10id Apr 1, 2023
1de56a0
Add rack-mini-profiler
Tab10id Apr 1, 2023
492c5b6
Add rack-mini-profiler study info
Tab10id Apr 1, 2023
f80e385
Fix N+1
Tab10id Apr 1, 2023
b21f534
Improve collection render
Tab10id Apr 2, 2023
aa452cb
Fix list of used instruments
Tab10id Apr 2, 2023
b98ea4f
Update task requirements
Tab10id Apr 2, 2023
aa1f6d4
Add stream import idea
Tab10id Apr 2, 2023
2ce3813
Enable gc for benchmark measure (was disabled by mistake)
Tab10id Apr 4, 2023
9952b56
Add oj parse
Tab10id Apr 3, 2023
2d271fd
Allow to parse gzipped files
Tab10id Apr 3, 2023
7ab2db6
Cleanup code
Tab10id Apr 3, 2023
e8a725c
Implement batch import from parse stream
Tab10id Apr 3, 2023
68694a2
Allow to set batch size in rake task
Tab10id Apr 3, 2023
ad0d363
Add stream parse and batch import study report
Tab10id Apr 3, 2023
c23164b
Add study report about activerecord cost
Tab10id Apr 3, 2023
d96981e
Add study report about bus import
Tab10id Apr 3, 2023
2e7adf3
Remove wrong assumption
Tab10id Apr 4, 2023
340123d
Add time results to study file
Tab10id Apr 4, 2023
da6397f
fix typo and style
Tab10id Apr 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'perfolab', github: 'Tab10id/perfolab', branch: :temp_26
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍 👍


gem "activerecord-import", "~> 1.4"

gem "rack-mini-profiler"
gem "oj", "~> 3.14"
34 changes: 33 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
GIT
remote: https://github.com/Tab10id/perfolab.git
revision: b75ed48af9aa69affc28a4034d47221a1690db26
branch: temp_26
specs:
perfolab (0.1.0)
memory_profiler (~> 1.0)
ruby-prof (~> 1.4, < 1.4.4)
stackprof (~> 0.2.0)
tabulo (~> 2.0)
zeitwerk (~> 2.6)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -33,6 +45,8 @@ GEM
activemodel (= 5.2.3)
activesupport (= 5.2.3)
arel (>= 9.0)
activerecord-import (1.4.1)
activerecord (>= 4.2)
activestorage (5.2.3)
actionpack (= 5.2.3)
activerecord (= 5.2.3)
Expand Down Expand Up @@ -67,18 +81,24 @@ GEM
mini_mime (>= 0.1.1)
marcel (0.3.3)
mimemagic (~> 0.3.2)
memory_profiler (1.0.1)
method_source (0.9.2)
mimemagic (0.3.3)
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mini_mime (1.0.1)
mini_portile2 (2.4.0)
minitest (5.11.3)
msgpack (1.2.9)
nio4r (2.3.1)
nokogiri (1.10.2)
mini_portile2 (~> 2.4.0)
oj (3.14.2)
pg (1.1.4)
puma (3.12.1)
rack (2.0.6)
rack-mini-profiler (3.0.0)
rack (>= 1.2.0)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (5.2.3)
Expand Down Expand Up @@ -109,6 +129,7 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
ruby-prof (1.4.3)
ruby_dep (1.5.0)
sprockets (3.7.2)
concurrent-ruby (~> 1.0)
Expand All @@ -117,10 +138,16 @@ GEM
actionpack (>= 4.0)
activesupport (>= 4.0)
sprockets (>= 3.0.0)
stackprof (0.2.24)
tabulo (2.8.2)
tty-screen (= 0.8.1)
unicode-display_width (~> 2.2)
thor (0.20.3)
thread_safe (0.3.6)
tty-screen (0.8.1)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (2.4.2)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
Expand All @@ -129,16 +156,21 @@ GEM
websocket-driver (0.7.0)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
zeitwerk (2.6.7)

PLATFORMS
ruby

DEPENDENCIES
activerecord-import (~> 1.4)
bootsnap (>= 1.1.0)
byebug
listen (>= 3.0.5, < 3.2)
oj (~> 3.14)
perfolab!
pg (>= 0.18, < 2.0)
puma (~> 3.11)
rack-mini-profiler
rails (~> 5.2.3)
tzinfo-data
web-console (>= 3.3.0)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/trips_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ class TripsController < ApplicationController
def index
@from = City.find_by_name!(params[:from])
@to = City.find_by_name!(params[:to])
@trips = Trip.where(from: @from, to: @to).order(:start_time)
@trips = Trip.where(from: @from, to: @to).preload(bus: :services).order(:start_time)
end
end
6 changes: 0 additions & 6 deletions app/views/trips/_services.html.erb

This file was deleted.

18 changes: 13 additions & 5 deletions app/views/trips/_trip.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<li><%= "Отправление: #{trip.start_time}" %></li>
<li><%= "Прибытие: #{(Time.parse(trip.start_time) + trip.duration_minutes.minutes).strftime('%H:%M')}" %></li>
<li><%= "В пути: #{trip.duration_minutes / 60}ч. #{trip.duration_minutes % 60}мин." %></li>
<li><%= "Цена: #{trip.price_cents / 100}р. #{trip.price_cents % 100}коп." %></li>
<li><%= "Автобус: #{trip.bus.model} №#{trip.bus.number}" %></li>
<ul>
<li><%= "Отправление: #{trip.start_time}" %></li>
<li><%= "Прибытие: #{(Time.parse(trip.start_time) + trip.duration_minutes.minutes).strftime('%H:%M')}" %></li>
<li><%= "В пути: #{trip.duration_minutes / 60}ч. #{trip.duration_minutes % 60}мин." %></li>
<li><%= "Цена: #{trip.price_cents / 100}р. #{trip.price_cents % 100}коп." %></li>
<li><%= "Автобус: #{trip.bus.model} №#{trip.bus.number}" %></li>
<% if trip.bus.services.present? %>
<li>Сервисы в автобусе:</li>
<ul>
<%= render partial: 'service', collection: trip.bus.services %>
</ul>
<% end %>
</ul>
10 changes: 1 addition & 9 deletions app/views/trips/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,4 @@
<%= "В расписании #{@trips.count} рейсов" %>
</h2>

<% @trips.each do |trip| %>
<ul>
<%= render "trip", trip: trip %>
<% if trip.bus.services.present? %>
<%= render "services", services: trip.bus.services %>
<% end %>
</ul>
<%= render "delimiter" %>
<% end %>
<%= render partial: 'trip', collection: @trips, spacer_template: 'delimiter' %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Идеально

Loading