Skip to content
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
16 changes: 16 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
env:
browser: true
node: true
es6: true
extends: 'eslint:recommended'
globals:
Atomics: readonly
SharedArrayBuffer: readonly
parserOptions:
ecmaFeatures:
jsx: true
ecmaVersion: 2018
sourceType: module
plugins:
- react
rules: {}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ coverage

# Ignore node_modules
node_modules/
false/

# Generated js bundles
/app/assets/javascripts/generated/*
Expand All @@ -36,6 +37,7 @@ latest.dump

# Ignore application configuration
/config/application.yml
config/new_relic.yml
/public/packs
/public/packs-test
/node_modules
Expand All @@ -52,4 +54,4 @@ package-lock.json
.idea/

#sitemap
/public/sitemap.xml.gz
/public/sitemap.xml.gz
2 changes: 2 additions & 0 deletions Envfile
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ variable :TRENDING_TAGS, :String, default: "git,beginners"
variable :FACEBOOK_PIXEL_ID, :String, default: "Optional"
variable :SMARTY_STREETS_WEB_KEY, :String, default: "Optional"

# New relic
variable :NEW_RELIC_LICENSE_KEY, :String, default: "Optional"

group :production do
variable :SECRET_KEY_BASE, :String
Expand Down
9 changes: 7 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ gem "sdoc", "~> 1.0", group: :doc
gem "serviceworker-rails", "~> 0.5"
gem "share_meow_client", "~> 0.1"
gem "sitemap_generator", "~> 6.0"
gem "skylight", "~> 3.1"
gem "skylight"
gem "slack-notifier", "~> 2.3"
gem "sprockets", "~> 3.7"
gem "staccato", "~> 0.5"
Expand Down Expand Up @@ -117,7 +117,7 @@ group :development do
gem "web-console", "~> 3.7"
end

group :development, :test do
group :development, :lp, :test do
gem "capybara", "~> 3.13"
gem "derailed", "~> 0.1"
gem "erb_lint", "~> 0.0", require: false
Expand All @@ -133,6 +133,7 @@ group :development, :test do
gem "spring", "~> 2.0"
gem "spring-commands-rspec", "~> 1.0"
gem "vcr", "~> 4.0"
gem 'meta_request'
end

group :test do
Expand All @@ -157,3 +158,7 @@ group :test do
gem "zonebie", "~> 0.6.1"
end
# rubocop:enable LineLength

gem 'newrelic_rpm'
gem 'prometheus_exporter'
gem 'rack-mini-profiler', require: false
19 changes: 18 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ GEM
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
base64 (0.1.1)
bcrypt (3.1.12)
benchmark-ips (2.7.2)
better_errors (2.5.0)
Expand Down Expand Up @@ -592,6 +593,9 @@ GEM
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
memory_profiler (0.9.12)
meta_request (0.7.4)
rack-contrib (>= 1.1, < 3)
railties (>= 3.0.0, < 7.1)
method_source (0.9.2)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
Expand All @@ -612,6 +616,8 @@ GEM
net-http-persistent (3.0.0)
connection_pool (~> 2.2)
netrc (0.11.0)
newrelic_rpm (9.6.0)
base64
nio4r (2.3.1)
nokogiri (1.10.1)
mini_portile2 (~> 2.4.0)
Expand Down Expand Up @@ -651,6 +657,8 @@ GEM
ast (~> 2.4.0)
pg (1.1.4)
powerpack (0.1.2)
prometheus_exporter (2.0.8)
webrick
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
Expand All @@ -675,8 +683,12 @@ GEM
pusher-signature (0.1.8)
raabro (1.1.6)
rack (2.0.6)
rack-contrib (2.4.0)
rack (< 4)
rack-host-redirect (1.3.0)
rack
rack-mini-profiler (3.1.1)
rack (>= 1.2.0)
rack-protection (2.0.4)
rack
rack-proxy (0.6.5)
Expand Down Expand Up @@ -932,6 +944,7 @@ GEM
webpush (0.3.2)
hkdf (~> 0.2)
jwt
webrick (1.8.1)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
Expand Down Expand Up @@ -1012,14 +1025,17 @@ DEPENDENCIES
libhoney (~> 1.11)
liquid (~> 4.0)
memory_profiler (~> 0.9)
meta_request
nakayoshi_fork
newrelic_rpm
nokogiri (~> 1.10)
octokit (~> 4.13)
omniauth (~> 1.9)
omniauth-github (~> 1.3)
omniauth-twitter (~> 1.4)
parallel_tests (~> 2.27)
pg (~> 1.1)
prometheus_exporter
pry (~> 0.12)
pry-byebug (~> 3.7)
pry-rails (~> 0.3)
Expand All @@ -1029,6 +1045,7 @@ DEPENDENCIES
pusher (~> 1.3)
pusher-push-notifications (~> 1.0)
rack-host-redirect (~> 1.3)
rack-mini-profiler
rack-timeout (~> 0.5)
rails (~> 5.1.6)
rails-assets-airbrake-js-client (~> 1.5)!
Expand Down Expand Up @@ -1057,7 +1074,7 @@ DEPENDENCIES
simplecov (~> 0.16)
sinatra (~> 2.0)
sitemap_generator (~> 6.0)
skylight (~> 3.1)
skylight
slack-notifier (~> 2.3)
spring (~> 2.0)
spring-commands-rspec (~> 1.0)
Expand Down
4 changes: 4 additions & 0 deletions Procfile.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
web: bin/rails s -p 3000 -e lp
webpacker: ./bin/webpack-dev-server
job: bin/rake jobs:work
prometheus_exporter: bundle exec prometheus_exporter
Binary file modified app/assets/images/sloan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion app/views/stories/_main_stories_feed.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
<% if !user_signed_in? && i == 4 %>
<%= render "stories/sign_in_invitation" %>
<% end %>
<%= render "articles/single_story", story: story %>
<% cache story do %>
<%= render "articles/single_story", story: story %>
<% end %>
<% end %>
<% end %>
<% if @stories.size > 1 %>
Expand Down
9 changes: 8 additions & 1 deletion bin/startup
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def system!(*args)
end

chdir APP_ROOT do
env = ENV.fetch('RAILS_ENV', 'development')
puts "== STARTING UP =="
system! "foreman start -f Procfile.dev"

if env == 'lp'
system! "bundle exec rake assets:precompile"
system! "foreman start -f Procfile.lp"
else
system! "foreman start -f Procfile.dev"
end
end
19 changes: 19 additions & 0 deletions case-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Оптимизация

## Кэширование `_single_story.html.erb` в `_main_stories_feed.html.erb`

Добавление кэширования по стори позволило ускорить загрузку главной страницы почти в 2 раза.

### AB

#### before

Time per request: 212.047 ms

https://gist.github.com/peresvetjke/22b0076f71bb49000aa3c3f082889d85

#### after

Time per request: 114.685 ms

https://gist.github.com/peresvetjke/5b0a328f332dda0c43c7d8466f927bde
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,7 @@ class Application < Rails::Application
end
ReservedWords.all = [ReservedWords::BASE_WORDS + top_routes].flatten.compact.uniq
end

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

Rails.application.configure do
# Verifies that versions and hashed value of the package contents in the project's package.json
config.webpacker.check_yarn_integrity = yarn_integrity_enabled?

# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = true

# Do not eager load code on boot.
config.eager_load = true

# Show full error reports and disable caching.
config.consider_all_requests_local = true

# Enable/disable caching. By default caching is disabled.
if Rails.root.join("tmp/caching-dev.txt").exist?
config.action_controller.perform_caching = true

config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=172800"
}
else
config.action_controller.perform_caching = false

config.cache_store = :null_store
end

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = false

# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = false

# Supress logger output for asset requests.
config.assets.quiet = true

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true

# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true

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"

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

config.public_file_server.enabled = true

config.file_watcher = ActiveSupport::EventedFileUpdateChecker

# Install the Timber.io logger
send_logs_to_timber = ENV["SEND_LOGS_TO_TIMBER"] || "false" # <---- set to false to stop sending dev logs to Timber.io
log_device = send_logs_to_timber == "true" ? Timber::LogDevices::HTTP.new(ENV["TIMBER"]) : STDOUT
logger = Timber::Logger.new(log_device)
logger.level = config.log_level
config.logger = ActiveSupport::TaggedLogging.new(logger)
end

# rubocop:enable Metrics/BlockLength
3 changes: 2 additions & 1 deletion config/initializers/airbrake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#
# Configuration details:
# https://github.com/airbrake/airbrake-ruby#configuration

Airbrake.configure do |c|
# You must set both project_id & project_key. To find your project_id and
# project_key navigate to your project's General Settings and copy the values
Expand Down Expand Up @@ -41,7 +42,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 lp]

# 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 %w[development test lp].include?(Rails.env)
config.storage = :file
else
# config.fog_provider = 'fog-aws'
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/honeycomb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
key = ApplicationConfig["HONEYCOMB_API_KEY"]
dataset = "dev.to-#{Rails.env}"

$libhoney = if Rails.env.development? || Rails.env.test?
$libhoney = if %w[development test lp].include?(Rails.env)
Libhoney::NullClient.new
else
Libhoney::Client.new(
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/prometheus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if Rails.env != "test"
require 'prometheus_exporter/middleware'

# This reports stats per request like HTTP status and timings
Rails.application.middleware.unshift PrometheusExporter::Middleware
end
9 changes: 9 additions & 0 deletions config/initializers/rack_mini_profiler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

if %w[development lp].include?(Rails.env)
require "rack-mini-profiler"

# The initializer was required late, so initialize it manually.
Rack::MiniProfilerRails.initialize!(Rails.application)
Rack::MiniProfiler.config.authorization_mode = :allow_all if Rails.env.lp?
end
Loading