Improving production logs, removing n+1 on media attachments in atom,

adding attachments display to static views
shrike
Eugen Rochko 2016-09-08 01:24:26 +02:00
parent 87576e1ab1
commit 0f4bc56719
7 changed files with 45 additions and 3 deletions

View File

@ -64,4 +64,5 @@ end
group :production do group :production do
gem 'rails_12factor' gem 'rails_12factor'
gem 'lograge'
end end

View File

@ -158,6 +158,10 @@ GEM
letter_opener (1.4.1) letter_opener (1.4.1)
launchy (~> 2.2) launchy (~> 2.2)
libv8 (3.16.14.15) libv8 (3.16.14.15)
lograge (0.4.1)
actionpack (>= 4, < 5.1)
activesupport (>= 4, < 5.1)
railties (>= 4, < 5.1)
loofah (2.0.3) loofah (2.0.3)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.4) mail (2.6.4)
@ -377,6 +381,7 @@ DEPENDENCIES
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
letter_opener letter_opener
lograge
nokogiri nokogiri
oj oj
onebox onebox

View File

@ -59,7 +59,7 @@ const MediaGallery = React.createClass({
} }
} }
return <a key={attachment.get('id')} href={attachment.get('url')} style={{ boxSizing: 'border-box', position: 'relative', left: left, top: top, right: right, bottom: bottom, float: 'left', textDecoration: 'none', border: 'none', display: 'block', width: `${width}%`, height: `${height}%`, background: `url(${attachment.get('preview_url')}) no-repeat center`, backgroundSize: 'cover', cursor: 'zoom-in' }} />; return <a key={attachment.get('id')} href={attachment.get('url')} target='_blank' style={{ boxSizing: 'border-box', position: 'relative', left: left, top: top, right: right, bottom: bottom, float: 'left', textDecoration: 'none', border: 'none', display: 'block', width: `${width}%`, height: `${height}%`, background: `url(${attachment.get('preview_url')}) no-repeat center`, backgroundSize: 'cover', cursor: 'zoom-in' }} />;
}); });
return ( return (

View File

@ -158,7 +158,7 @@
font-size: 14px; font-size: 14px;
padding: 0 10px; padding: 0 10px;
padding-left: 8px; padding-left: 8px;
padding-bottom: 25px; padding-bottom: 15px;
color: #282c37; color: #282c37;
a { a {
@ -189,4 +189,33 @@
text-decoration: underline; text-decoration: underline;
} }
} }
.media-attachments {
list-style: none;
margin: 0;
padding: 0;
display: block;
overflow: hidden;
padding-left: 10px;
li {
display: block;
float: left;
width: 120px;
height: 100px;
border-radius: 4px;
margin-right: 4px;
margin-bottom: 25px;
a {
display: block;
width: 120px;
height: 100px;
border-radius: 4px;
background-position: center;
background-repeat: none;
background-size: cover;
}
}
}
} }

View File

@ -11,7 +11,7 @@ class AccountsController < ApplicationController
format.atom do format.atom do
@entries = @account.stream_entries.order('id desc').with_includes.paginate_by_max_id(20, params[:max_id] || nil) @entries = @account.stream_entries.order('id desc').with_includes.paginate_by_max_id(20, params[:max_id] || nil)
ActiveRecord::Associations::Preloader.new.preload(@entries.select { |a| a.activity_type == 'Status' }, activity: [:mentions, reblog: :account, thread: :account]) ActiveRecord::Associations::Preloader.new.preload(@entries.select { |a| a.activity_type == 'Status' }, activity: [:mentions, :media_attachments, reblog: :account, thread: :account])
ActiveRecord::Associations::Preloader.new.preload(@entries.select { |a| a.activity_type == 'Favourite' }, activity: [:account, :status]) ActiveRecord::Associations::Preloader.new.preload(@entries.select { |a| a.activity_type == 'Favourite' }, activity: [:account, :status])
ActiveRecord::Associations::Preloader.new.preload(@entries.select { |a| a.activity_type == 'Follow' }, activity: :target_account) ActiveRecord::Associations::Preloader.new.preload(@entries.select { |a| a.activity_type == 'Follow' }, activity: :target_account)
end end

View File

@ -38,6 +38,10 @@
.content= content_for_status(proper_status(status)) .content= content_for_status(proper_status(status))
%ul.media-attachments
- status.media_attachments.each do |media|
%li.transparent-background= link_to '', media.file.url, style: "background-image: url(#{media.file.url(:small)})", target: '_blank'
- if include_threads - if include_threads
- status.descendants.with_includes.with_counters.each do |status| - status.descendants.with_includes.with_counters.each do |status|
= render partial: 'status', locals: { status: status, is_successor: true } = render partial: 'status', locals: { status: status, is_successor: true }

View File

@ -64,6 +64,9 @@ Rails.application.configure do
# Use default logging formatter so that PID and timestamp are not suppressed. # Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new config.log_formatter = ::Logger::Formatter.new
# Better log formatting
config.lograge.enabled = true
# Do not dump schema after migrations. # Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false config.active_record.dump_schema_after_migration = false