Improving feed queries, switching API to doorkeeper authentication
This commit is contained in:
parent
b919f39b31
commit
447cfef62d
12 changed files with 50 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
class Api::AccountsController < ApiController
|
||||
before_action :set_account
|
||||
before_action :authenticate_user!
|
||||
before_action :doorkeeper_authorize!
|
||||
respond_to :json
|
||||
|
||||
def show
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Api::FollowsController < ApiController
|
||||
before_action :authenticate_user!
|
||||
before_action :doorkeeper_authorize!
|
||||
respond_to :json
|
||||
|
||||
def create
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Api::StatusesController < ApiController
|
||||
before_action :authenticate_user!
|
||||
before_action :doorkeeper_authorize!
|
||||
respond_to :json
|
||||
|
||||
def show
|
||||
|
|
|
@ -4,7 +4,7 @@ class ApiController < ApplicationController
|
|||
protected
|
||||
|
||||
def current_resource_owner
|
||||
User.find(doorkeeper_token.user_id) if doorkeeper_token
|
||||
User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
|
||||
end
|
||||
|
||||
def current_user
|
||||
|
|
|
@ -23,8 +23,9 @@ module StreamEntriesHelper
|
|||
def linkify(status)
|
||||
mention_hash = {}
|
||||
status.mentions.each { |m| mention_hash[m.acct] = m }
|
||||
coder = HTMLEntities.new
|
||||
|
||||
auto_link(CGI.escapeHTML(status.text), link: :urls, html: { target: '_blank', rel: 'nofollow' }).gsub(Account::MENTION_RE) do |m|
|
||||
auto_link(coder.encode(status.text), link: :urls, html: { target: '_blank', rel: 'nofollow' }).gsub(Account::MENTION_RE) do |m|
|
||||
account = mention_hash[Account::MENTION_RE.match(m)[1]]
|
||||
"#{m.split('@').first}<a href=\"#{url_for_target(account)}\" class=\"mention\">@<span>#{account.acct}</span></a>"
|
||||
end.html_safe
|
||||
|
|
|
@ -11,7 +11,7 @@ class Feed
|
|||
# If we're after most recent items and none are there, we need to precompute the feed
|
||||
return PrecomputeFeedService.new.(@type, @account).take(limit) if unhydrated.empty? && offset == 0
|
||||
|
||||
Status.where(id: unhydrated).each { |status| status_map[status.id.to_s] = status }
|
||||
Status.where(id: unhydrated).with_includes.with_counters.each { |status| status_map[status.id.to_s] = status }
|
||||
return unhydrated.map { |id| status_map[id] }
|
||||
end
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@ class Status < ActiveRecord::Base
|
|||
validates :account, presence: true
|
||||
validates :uri, uniqueness: true, unless: 'local?'
|
||||
|
||||
scope :with_counters, -> { select('statuses.*, (select count(r.id) from statuses as r where r.reblog_of_id = statuses.id) as reblogs_count, (select count(f.id) from favourites as f where f.status_id = statuses.id) as favourites_count') }
|
||||
scope :with_includes, -> { includes(:account, reblog: :account, thread: :account) }
|
||||
|
||||
def local?
|
||||
self.uri.nil?
|
||||
end
|
||||
|
|
|
@ -18,11 +18,11 @@ class PrecomputeFeedService < BaseService
|
|||
end
|
||||
|
||||
def home(account)
|
||||
Status.where(account: [account] + account.following)
|
||||
Status.where(account: [account] + account.following).with_includes.with_counts
|
||||
end
|
||||
|
||||
def mentions(account)
|
||||
Status.where(id: Mention.where(account: account).pluck(:status_id))
|
||||
Status.where(id: Mention.where(account: account).pluck(:status_id)).with_includes.with_counts
|
||||
end
|
||||
|
||||
def key(type, id)
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
.header__right
|
||||
.counter-btn{ class: reblogged_by_me_class(status) }
|
||||
%i.fa.fa-retweet
|
||||
%span.counter-number= status.reblog? ? status.reblog.reblogs.count : status.reblogs.count
|
||||
%span.counter-number= status.reblog? ? status.reblog.reblogs.count : status.reblogs_count
|
||||
.counter-btn{ class: favourited_by_me_class(status) }
|
||||
%i.fa.fa-star
|
||||
%span.counter-number= status.reblog? ? status.reblog.favourites.count : status.favourites.count
|
||||
%span.counter-number= status.reblog? ? status.reblog.favourites.count : status.favourites_count
|
||||
.content
|
||||
= status.reblog? ? (status.reblog.local? ? linkify(status.reblog) : status.reblog.content.html_safe) : (status.local? ? linkify(status) : status.content.html_safe)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue