Commit 1ee35687 authored by Eugen Rochko's avatar Eugen Rochko

Update dependencies, add timeouts to requests, fix n+1 query, enable lograge

parent 65fc6a4f
......@@ -12,7 +12,7 @@ gem 'jquery-rails'
gem 'uglifier'
gem 'bootsnap'
gem 'mastodon-api', require: 'mastodon'
gem 'mastodon-api', require: 'mastodon', git: 'https://github.com/tootsuite/mastodon-api'
gem 'twitter', git: 'https://github.com/sferik/twitter'
gem 'devise', '~> 4.3'
gem 'omniauth-twitter'
......
GIT
remote: https://github.com/sferik/twitter
revision: bc911e9106012aa0ef4d8b0b92ef05b880ed6da9
revision: d6c5100447e2c12d83bae26810632081ac0b69f5
specs:
twitter (5.15.0)
twitter (6.2.0)
addressable (~> 2.3)
buftok (~> 0.2.0)
equalizer (~> 0.0.11)
http (~> 2.0)
http-form_data (~> 1.0)
http (~> 3.0)
http-form_data (~> 2.0)
http_parser.rb (~> 0.6.0)
memoizable (~> 0.4.0)
multipart-post (~> 2.0)
naught (~> 1.0)
simple_oauth (~> 0.3.0)
GIT
remote: https://github.com/tootsuite/mastodon-api
revision: 6557c5cc580f611c75da5f77280ec1dc571d08e0
specs:
mastodon-api (1.2.0)
addressable (~> 2.5)
buftok
http (~> 3.0)
oj (~> 3.3)
GEM
remote: https://rubygems.org/
specs:
......@@ -108,14 +118,14 @@ GEM
railties (>= 4.0.1)
hashie (3.5.6)
hiredis (0.6.1)
http (2.2.2)
http (3.0.0)
addressable (~> 2.3)
http-cookie (~> 1.0)
http-form_data (~> 1.0.1)
http-form_data (>= 2.0.0.pre.pre2, < 3)
http_parser.rb (~> 0.6.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
http-form_data (1.0.3)
http-form_data (2.0.0)
http_parser.rb (0.6.0)
httplog (0.99.7)
colorize
......@@ -139,9 +149,6 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.6)
mime-types (>= 1.16, < 4)
mastodon-api (1.1.0)
addressable (~> 2.4)
http (~> 2.0)
memoizable (0.4.2)
thread_safe (~> 0.3, >= 0.3.1)
method_source (0.8.2)
......@@ -311,7 +318,7 @@ DEPENDENCIES
jquery-rails
listen (~> 3.0.5)
lograge (~> 0.5)
mastodon-api
mastodon-api!
oj
omniauth-mastodon (>= 0.9.2)
omniauth-twitter
......
......@@ -33,7 +33,7 @@ class FriendsController < ApplicationController
def set_friends
@friends = User.where(id: Authorization.where(provider: :twitter, uid: twitter_friend_ids).map(&:user_id))
.includes(:authorizations)
.includes(:twitter, :mastodon)
.reject { |user| user.mastodon.nil? }
end
......
......@@ -17,7 +17,7 @@ class MastodonClient < ApplicationRecord
def client_token
return attributes['client_token'] if attributes['client_token'].present?
res = HTTP.post("https://#{domain}/oauth/token", params: {
res = http_client.post("https://#{domain}/oauth/token", params: {
grant_type: 'client_credentials',
client_id: client_id,
client_secret: client_secret,
......@@ -34,7 +34,13 @@ class MastodonClient < ApplicationRecord
def still_valid?
return false if client_token.blank?
res = HTTP.get("https://#{domain}/api/v1/apps/verify_credentials", headers: { 'Authorization': "Bearer #{client_token}" })
res = http_client.get("https://#{domain}/api/v1/apps/verify_credentials", headers: { 'Authorization': "Bearer #{client_token}" })
res.code == 200
end
private
def http_client
HTTP.timeout(:per_operation, connect: 2, read: 5, write: 5)
end
end
......@@ -5,11 +5,10 @@ class User < ApplicationRecord
has_many :authorizations
attr_accessor :relative_account_id, :following
has_one :twitter, -> { where(provider: 'twitter') }, class_name: 'Authorization'
has_one :mastodon, -> { where(provider: 'mastodon') }, class_name: 'Authorization'
def twitter
@twitter ||= authorizations.where(provider: :twitter).last
end
attr_accessor :relative_account_id, :following
def twitter_client
return if twitter.nil?
......@@ -22,10 +21,6 @@ class User < ApplicationRecord
end
end
def mastodon
@mastodon ||= authorizations.where(provider: :mastodon).last
end
def mastodon_client
return if mastodon.nil?
......
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.lograge.enabled = true
# Code is not reloaded between requests.
config.cache_classes = true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment