Skip to content

ДЗ 5 #93

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 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ latest.dump
.gitdocs_build/

# Ignore application configuration
/config/application.yml
config/application.yml
config/database.yml
config/secrets.yml
/public/packs
/public/packs-test
/node_modules
config/database.yml

# Ignore storybook static site generation
storybook-static/
Expand All @@ -48,8 +49,10 @@ yarn-error.log
# Ignore package-lock.json because we use yarn
package-lock.json

#Jetbrains Tools
.idea/
.vscode

#sitemap
/public/sitemap.xml.gz
/public/sitemap.xml.gz

sitespeed-result/
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
thinknetica
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.1
ruby-2.6.1
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ end
gem "actionpack-action_caching", "~> 1.2"
gem "active_record_union", "~> 1.3"
gem "acts-as-taggable-on", "~> 5.0"
gem "acts_as_follower", github: "thepracticaldev/acts_as_follower", branch: "master"
# gem "acts_as_follower", github: "thepracticaldev/acts_as_follower", branch: "master"
gem 'acts_as_follower', github: 'tcocca/acts_as_follower', branch: 'master'
gem "addressable", "~> 2.5", ">= 2.5.2"
gem "administrate", "~> 0.11"
gem "ahoy_email", "~> 0.5"
Expand Down Expand Up @@ -117,12 +118,13 @@ group :development do
gem "web-console", "~> 3.7"
end

group :development, :test do
group :development, :local_production, :test do
gem "capybara", "~> 3.13"
gem "derailed", "~> 0.1"
gem "erb_lint", "~> 0.0", require: false
gem "faker", git: "https://github.com/stympy/faker.git", branch: "master"
gem "fix-db-schema-conflicts", github: "thepracticaldev/fix-db-schema-conflicts", branch: "master"
# gem "fix-db-schema-conflicts", github: "thepracticaldev/fix-db-schema-conflicts", branch: "master"
gem "fix-db-schema-conflicts"
gem "memory_profiler", "~> 0.9"
gem "parallel_tests", "~> 2.27"
gem "pry-byebug", "~> 3.7"
Expand Down
16 changes: 5 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,13 @@ GIT
i18n (>= 0.7)

GIT
remote: https://github.com/thepracticaldev/acts_as_follower.git
revision: 288690cd99bc470eaee493fce5bfa9fe23157692
remote: https://github.com/tcocca/acts_as_follower.git
revision: c5ac7b9601c4af01eb4d9112330b27be4d694ecc
branch: master
specs:
acts_as_follower (0.2.1)
activerecord (>= 4.0)

GIT
remote: https://github.com/thepracticaldev/fix-db-schema-conflicts.git
revision: 4172392392e1a8d907f7ab673cb5ddd9a4a31940
branch: master
specs:
fix-db-schema-conflicts (3.0.2)
rubocop (>= 0.38.0)

GEM
remote: https://rubygems.org/
remote: https://rails-assets.org/
Expand Down Expand Up @@ -322,6 +314,8 @@ GEM
thor (~> 0.14)
fission (0.5.0)
CFPropertyList (~> 2.2)
fix-db-schema-conflicts (3.1.0)
rubocop (>= 0.38.0)
fog (1.41.0)
fog-aliyun (>= 0.1.0)
fog-atmos
Expand Down Expand Up @@ -992,7 +986,7 @@ DEPENDENCIES
fastly-rails (~> 0.8)
feedjira (~> 2.2)
figaro (~> 1.1)
fix-db-schema-conflicts!
fix-db-schema-conflicts
fog (~> 1.41)
front_matter_parser (~> 0.2)
gemoji (~> 3.0.0)
Expand Down
4 changes: 4 additions & 0 deletions Procfile.locprod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
web: bin/rails s -p 3000
webpacker: ./bin/webpack-dev-server
job: bin/rake jobs:work
# prometheus_exporter: bundle exec prometheus_exporter
12 changes: 12 additions & 0 deletions app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ def index
return handle_user_or_organization_or_podcast_index if params[:username]
return handle_tag_index if params[:tag]

push_headers = [
"<#{view_context.asset_path('bell.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('menu.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('connect.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('stack.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('lightning.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('devplain.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('sloan.png')}>; rel=preload; as=image",
Copy link
Collaborator

Choose a reason for hiding this comment

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

кажется вы многовато всего запрелоадили

так мы проиграем думаю в воспринимаемой скорости загрузки сайта, потратим время на загрузку некритичных картинок

"<#{view_context.asset_path('twitter-logo.svg')}>; rel=preload; as=image",
"<#{view_context.asset_path('github-logo.svg')}>; rel=preload; as=image",
]
response.headers["Link"] = push_headers.join(", ")
handle_base_index
end

Expand Down
8 changes: 4 additions & 4 deletions app/views/layouts/_top_bar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="top-bar" id="top-bar">
<nav>
<a href="#articles-list" class="skip-content-link">Skip to content</a>
<a href="/" class="logo-link" id="logo-link" aria-label="DEV Home"><%= inline_svg("devplain.svg", class: "logo", size: "20% * 20%") %></a>
<a href="/" class="logo-link" id="logo-link" aria-label="DEV Home"><%= image_tag("devplain.svg", class: "logo", size: "20% * 20%") %></a>
<div id="nav-search-form-root">
<div class="nav-search-form">
<form acceptCharset="UTF-8" method="get">
Expand All @@ -13,19 +13,19 @@
</div>
<a href="/new" id="write-link" class="cta nav-link write">WRITE A POST</a>
<a href="/connect" id="connect-link" class="nav-link connect-icon" aria-label="Connect">
<%= inline_svg("connect.svg", size: "100% * 100%") %>
<%= image_tag("connect.svg", size: "100% * 100%") %>
<div class="connect-number" id="connect-number"></div>
</a>
<a href="/notifications" id="notifications-link" class="nav-link notifications-icon" aria-label="Notifications">
<%= inline_svg("bell.svg", size: "100% * 100%") %>
<%= image_tag("bell.svg", size: "100% * 100%") %>
<div class="notifications-number" id="notifications-number"></div>
</a>
<div class="navbar-menu-wrapper" id="navbar-menu-wrapper">
<button class="navigation-butt" id="navigation-butt" aria-label="Navigation">
<% if user_signed_in? %>
<div class="nav-profile-image-wrapper"><img alt="" class="nav-profile-image" id="nav-profile-image" /></div>
<% else %>
<%= inline_svg("menu.svg", class: "bars", size: "20% * 20%") %>
<%= image_tag("menu.svg", class: "bars", size: "20% * 20%") %>
<% end %>
</button>
<div class="menubg" id="menubg"></div>
Expand Down
1 change: 1 addition & 0 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ chdir APP_ROOT do
# This solution was found here https://github.com/rails/rails/issues/26731#issuecomment-302446525
# This line is to remove manual need to run a separate manual migration upon calling rspec
system! "RAILS_ENV=test bin/rails db:environment:set"
system! "RAILS_ENV=local_production bin/rails db:environment:set"

puts "\n== Removing old logs and tempfiles =="
system! "bin/rails log:clear tmp:clear"
Expand Down
18 changes: 18 additions & 0 deletions bin/startup_local_production
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env ruby
require "pathname"
require "fileutils"
include FileUtils

# path to your application root.
APP_ROOT = Pathname.new File.expand_path("..", __dir__)
ENV["RAILS_ENV"] = 'local_production'

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end

chdir APP_ROOT do
puts "== STARTING UP =="
system! "bundle exec rake assets:precompile"
system! "foreman start -f Procfile.locprod"
end
1 change: 1 addition & 0 deletions browsertime_w_push.har

Large diffs are not rendered by default.

Binary file added browsertime_w_push.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions browsertime_wo_push.har

Large diffs are not rendered by default.

Binary file added browsertime_wo_push.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions case-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Подготовка

- [x] Настройка окружения `local_production`
- [x] Настройка сертификата для локального HTTPS с использованием `mkcert`
- [x] Настройка NGinx как reverse-proxy
- [x] Настройка HTTP/2 и server-push

## Измерение эффекта сделанных изменений

### Анализ версии без server-push

![alt text](browsertime_wo_push.png 'Browser time without push')

### Анализ с server-push

![alt text](browsertime_w_push.png 'Browser time with push')
92 changes: 0 additions & 92 deletions config/database.yml.sample

This file was deleted.

54 changes: 54 additions & 0 deletions config/environments/local_production.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# rubocop:disable Metrics/BlockLength
#
def yarn_integrity_enabled?
ENV.fetch("YARN_INTEGRITY_ENABLED", "true") == "true"
end

Rails.application.configure do
config.webpacker.check_yarn_integrity = false
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.enabled = true
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=172800"
}
config.assets.js_compressor = Uglifier.new(harmony: true)
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.compile = true
config.assets.debug = false
config.assets.digest = true
config.assets.quiet = true
config.assets.raise_runtime_errors = true
config.log_formatter = ::Logger::Formatter.new
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.action_mailer.perform_caching = false
config.app_domain = "localhost:3000"
config.action_mailer.default_url_options = { host: "localhost:3000" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { host: config.app_domain }
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: "587",
enable_starttls_auto: true,
user_name: '<%= ENV["DEVELOPMENT_EMAIL_USERNAME"] %>',
password: '<%= ENV["DEVELOPMENT_EMAIL_PASSWORD"] %>',
authentication: :plain,
domain: "localhost:3000"
}
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
config.log_level = :debug
config.log_tags = [:request_id]
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end

# rubocop:enable Metrics/BlockLength
2 changes: 1 addition & 1 deletion config/initializers/airbrake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# environments.
# NOTE: This option *does not* work if you don't set the 'environment' option.
# https://github.com/airbrake/airbrake-ruby#ignore_environments
c.ignore_environments = %w[test development]
c.ignore_environments = %w[test development local_production]

# A list of parameters that should be filtered out of what is sent to
# Airbrake. By default, all "password" attributes will have their contents
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/carrierwave.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "carrierwave/storage/fog"

CarrierWave.configure do |config|
if Rails.env.development? || Rails.env.test?
if Rails.env.development? || Rails.env.test? || Rails.env.local_production?
config.storage = :file
else
# config.fog_provider = 'fog-aws'
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/timeout.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if Rails.env.development? && ENV["RACK_TIMEOUT_WAIT_TIMEOUT"].nil?
if (Rails.env.development? || Rails.env.local_production?) && ENV["RACK_TIMEOUT_WAIT_TIMEOUT"].nil?
ENV["RACK_TIMEOUT_WAIT_TIMEOUT"] = "100000"
ENV["RACK_TIMEOUT_SERVICE_TIMEOUT"] = "100000"
end
Expand Down
17 changes: 0 additions & 17 deletions config/sample_application.yml

This file was deleted.

2 changes: 2 additions & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ test:
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>

local_production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
Loading