Slightly reduce RAM usage (#7301)
* No need to re-require sidekiq plugins, they are required via Gemfile * Add derailed_benchmarks tool, no need to require TTY gems in Gemfile * Replace ruby-oembed with FetchOEmbedService Reduce startup by 45382 allocated objects * Remove preloaded JSON-LD in favour of caching HTTP responses Reduce boot RAM by about 6 MiB * Fix tests * Fix test suite by stubbing out JSON-LD contexts
This commit is contained in:
parent
71a7cea73f
commit
cb5b5cb5f7
76 changed files with 784 additions and 471 deletions
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe AccountSearchService do
|
||||
describe AccountSearchService, type: :service do
|
||||
describe '.call' do
|
||||
describe 'with a query to ignore' do
|
||||
it 'returns empty array for missing query' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::FetchRemoteAccountService do
|
||||
RSpec.describe ActivityPub::FetchRemoteAccountService, type: :service do
|
||||
subject { ActivityPub::FetchRemoteAccountService.new }
|
||||
|
||||
let!(:actor) do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::FetchRemoteStatusService do
|
||||
RSpec.describe ActivityPub::FetchRemoteStatusService, type: :service do
|
||||
include ActionView::Helpers::TextHelper
|
||||
|
||||
let(:sender) { Fabricate(:account) }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::ProcessAccountService do
|
||||
RSpec.describe ActivityPub::ProcessAccountService, type: :service do
|
||||
subject { described_class.new }
|
||||
|
||||
context 'property values' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::ProcessCollectionService do
|
||||
RSpec.describe ActivityPub::ProcessCollectionService, type: :service do
|
||||
let(:actor) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') }
|
||||
|
||||
let(:payload) do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AfterBlockService do
|
||||
RSpec.describe AfterBlockService, type: :service do
|
||||
subject do
|
||||
-> { described_class.new.call(account, target_account) }
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AuthorizeFollowService do
|
||||
RSpec.describe AuthorizeFollowService, type: :service do
|
||||
let(:sender) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
subject { AuthorizeFollowService.new }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe BatchedRemoveStatusService do
|
||||
RSpec.describe BatchedRemoveStatusService, type: :service do
|
||||
subject { BatchedRemoveStatusService.new }
|
||||
|
||||
let!(:alice) { Fabricate(:account) }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe BlockDomainFromAccountService do
|
||||
RSpec.describe BlockDomainFromAccountService, type: :service do
|
||||
let!(:wolf) { Fabricate(:account, username: 'wolf', domain: 'evil.org') }
|
||||
let!(:alice) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe BlockDomainService do
|
||||
RSpec.describe BlockDomainService, type: :service do
|
||||
let(:bad_account) { Fabricate(:account, username: 'badguy666', domain: 'evil.org') }
|
||||
let(:bad_status1) { Fabricate(:status, account: bad_account, text: 'You suck') }
|
||||
let(:bad_status2) { Fabricate(:status, account: bad_account, text: 'Hahaha') }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe BlockService do
|
||||
RSpec.describe BlockService, type: :service do
|
||||
let(:sender) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
subject { BlockService.new }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe BootstrapTimelineService do
|
||||
RSpec.describe BootstrapTimelineService, type: :service do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#call' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FanOutOnWriteService do
|
||||
RSpec.describe FanOutOnWriteService, type: :service do
|
||||
let(:author) { Fabricate(:account, username: 'tom') }
|
||||
let(:status) { Fabricate(:status, text: 'Hello @alice #test', account: author) }
|
||||
let(:alice) { Fabricate(:user, account: Fabricate(:account, username: 'alice')).account }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FavouriteService do
|
||||
RSpec.describe FavouriteService, type: :service do
|
||||
let(:sender) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
subject { FavouriteService.new }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FetchAtomService do
|
||||
RSpec.describe FetchAtomService, type: :service do
|
||||
describe '#call' do
|
||||
let(:url) { 'http://example.com' }
|
||||
subject { FetchAtomService.new.call(url) }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FetchLinkCardService do
|
||||
RSpec.describe FetchLinkCardService, type: :service do
|
||||
subject { FetchLinkCardService.new }
|
||||
|
||||
before do
|
||||
|
|
125
spec/services/fetch_oembed_service_spec.rb
Normal file
125
spec/services/fetch_oembed_service_spec.rb
Normal file
|
@ -0,0 +1,125 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe FetchOEmbedService, type: :service do
|
||||
subject { described_class.new }
|
||||
|
||||
before do
|
||||
stub_request(:get, "https://host.test/provider.json").to_return(status: 404)
|
||||
stub_request(:get, "https://host.test/provider.xml").to_return(status: 404)
|
||||
end
|
||||
|
||||
describe 'discover_provider' do
|
||||
context 'when status code is 200 and MIME type is text/html' do
|
||||
context 'Both of JSON and XML provider are discoverable' do
|
||||
before do
|
||||
stub_request(:get, 'https://host.test/oembed.html').to_return(
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'text/html' },
|
||||
body: request_fixture('oembed_json_xml.html')
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns new OEmbed::Provider for JSON provider if :format option is set to :json' do
|
||||
subject.call('https://host.test/oembed.html', format: :json)
|
||||
expect(subject.endpoint_url).to eq 'https://host.test/provider.json'
|
||||
expect(subject.format).to eq :json
|
||||
end
|
||||
|
||||
it 'returns new OEmbed::Provider for XML provider if :format option is set to :xml' do
|
||||
subject.call('https://host.test/oembed.html', format: :xml)
|
||||
expect(subject.endpoint_url).to eq 'https://host.test/provider.xml'
|
||||
expect(subject.format).to eq :xml
|
||||
end
|
||||
end
|
||||
|
||||
context 'JSON provider is discoverable while XML provider is not' do
|
||||
before do
|
||||
stub_request(:get, 'https://host.test/oembed.html').to_return(
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'text/html' },
|
||||
body: request_fixture('oembed_json.html')
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns new OEmbed::Provider for JSON provider' do
|
||||
subject.call('https://host.test/oembed.html')
|
||||
expect(subject.endpoint_url).to eq 'https://host.test/provider.json'
|
||||
expect(subject.format).to eq :json
|
||||
end
|
||||
end
|
||||
|
||||
context 'XML provider is discoverable while JSON provider is not' do
|
||||
before do
|
||||
stub_request(:get, 'https://host.test/oembed.html').to_return(
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'text/html' },
|
||||
body: request_fixture('oembed_xml.html')
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns new OEmbed::Provider for XML provider' do
|
||||
subject.call('https://host.test/oembed.html')
|
||||
expect(subject.endpoint_url).to eq 'https://host.test/provider.xml'
|
||||
expect(subject.format).to eq :xml
|
||||
end
|
||||
end
|
||||
|
||||
context 'Invalid XML provider is discoverable while JSON provider is not' do
|
||||
before do
|
||||
stub_request(:get, 'https://host.test/oembed.html').to_return(
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'text/html' },
|
||||
body: request_fixture('oembed_invalid_xml.html')
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns nil' do
|
||||
expect(subject.call('https://host.test/oembed.html')).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'Neither of JSON and XML provider is discoverable' do
|
||||
before do
|
||||
stub_request(:get, 'https://host.test/oembed.html').to_return(
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'text/html' },
|
||||
body: request_fixture('oembed_undiscoverable.html')
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns nil' do
|
||||
expect(subject.call('https://host.test/oembed.html')).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status code is not 200' do
|
||||
before do
|
||||
stub_request(:get, 'https://host.test/oembed.html').to_return(
|
||||
status: 400,
|
||||
headers: { 'Content-Type': 'text/html' },
|
||||
body: request_fixture('oembed_xml.html')
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns nil' do
|
||||
expect(subject.call('https://host.test/oembed.html')).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when MIME type is not text/html' do
|
||||
before do
|
||||
stub_request(:get, 'https://host.test/oembed.html').to_return(
|
||||
status: 200,
|
||||
body: request_fixture('oembed_xml.html')
|
||||
)
|
||||
end
|
||||
|
||||
it 'returns nil' do
|
||||
expect(subject.call('https://host.test/oembed.html')).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FetchRemoteAccountService do
|
||||
RSpec.describe FetchRemoteAccountService, type: :service do
|
||||
let(:url) { 'https://example.com' }
|
||||
let(:prefetched_body) { nil }
|
||||
let(:protocol) { :ostatus }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FetchRemoteStatusService do
|
||||
RSpec.describe FetchRemoteStatusService, type: :service do
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:prefetched_body) { nil }
|
||||
let(:valid_domain) { Rails.configuration.x.local_domain }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe FollowService do
|
||||
RSpec.describe FollowService, type: :service do
|
||||
let(:sender) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
subject { FollowService.new }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe MuteService do
|
||||
RSpec.describe MuteService, type: :service do
|
||||
subject do
|
||||
-> { described_class.new.call(account, target_account) }
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe NotifyService do
|
||||
RSpec.describe NotifyService, type: :service do
|
||||
subject do
|
||||
-> { described_class.new.call(recipient, activity) }
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe PostStatusService do
|
||||
RSpec.describe PostStatusService, type: :service do
|
||||
subject { PostStatusService.new }
|
||||
|
||||
it 'creates a new status' do
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe PrecomputeFeedService do
|
||||
RSpec.describe PrecomputeFeedService, type: :service do
|
||||
subject { PrecomputeFeedService.new }
|
||||
|
||||
describe 'call' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ProcessFeedService do
|
||||
RSpec.describe ProcessFeedService, type: :service do
|
||||
subject { ProcessFeedService.new }
|
||||
|
||||
describe 'processing a feed' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ProcessInteractionService do
|
||||
RSpec.describe ProcessInteractionService, type: :service do
|
||||
let(:receiver) { Fabricate(:user, email: 'alice@example.com', account: Fabricate(:account, username: 'alice')).account }
|
||||
let(:sender) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob')).account }
|
||||
let(:remote_sender) { Fabricate(:account, username: 'carol', domain: 'localdomain.com', uri: 'https://webdomain.com/users/carol') }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ProcessMentionsService do
|
||||
RSpec.describe ProcessMentionsService, type: :service do
|
||||
let(:account) { Fabricate(:account, username: 'alice') }
|
||||
let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct}") }
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Pubsubhubbub::SubscribeService do
|
||||
describe Pubsubhubbub::SubscribeService, type: :service do
|
||||
describe '#call' do
|
||||
subject { described_class.new }
|
||||
let(:user_account) { Fabricate(:account) }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Pubsubhubbub::UnsubscribeService do
|
||||
describe Pubsubhubbub::UnsubscribeService, type: :service do
|
||||
describe '#call' do
|
||||
subject { described_class.new }
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ReblogService do
|
||||
RSpec.describe ReblogService, type: :service do
|
||||
let(:alice) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
context 'OStatus' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RejectFollowService do
|
||||
RSpec.describe RejectFollowService, type: :service do
|
||||
let(:sender) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
subject { RejectFollowService.new }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe RemoveStatusService do
|
||||
RSpec.describe RemoveStatusService, type: :service do
|
||||
subject { RemoveStatusService.new }
|
||||
|
||||
let!(:alice) { Fabricate(:account) }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ReportService do
|
||||
RSpec.describe ReportService, type: :service do
|
||||
subject { described_class.new }
|
||||
|
||||
let(:source_account) { Fabricate(:account) }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ResolveAccountService do
|
||||
RSpec.describe ResolveAccountService, type: :service do
|
||||
subject { described_class.new }
|
||||
|
||||
before do
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe ResolveURLService do
|
||||
describe ResolveURLService, type: :service do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#call' do
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe SearchService do
|
||||
describe SearchService, type: :service do
|
||||
subject { described_class.new }
|
||||
|
||||
describe '#call' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SendInteractionService do
|
||||
RSpec.describe SendInteractionService, type: :service do
|
||||
subject { SendInteractionService.new }
|
||||
|
||||
it 'sends an XML envelope to the Salmon end point of remote user'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SubscribeService do
|
||||
RSpec.describe SubscribeService, type: :service do
|
||||
let(:account) { Fabricate(:account, username: 'bob', domain: 'example.com', hub_url: 'http://hub.example.com') }
|
||||
subject { SubscribeService.new }
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SuspendAccountService do
|
||||
RSpec.describe SuspendAccountService, type: :service do
|
||||
describe '#call' do
|
||||
subject do
|
||||
-> { described_class.new.call(account) }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
describe UnblockDomainService do
|
||||
describe UnblockDomainService, type: :service do
|
||||
subject { described_class.new }
|
||||
|
||||
describe 'call' do
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UnblockService do
|
||||
RSpec.describe UnblockService, type: :service do
|
||||
let(:sender) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
subject { UnblockService.new }
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UnfollowService do
|
||||
RSpec.describe UnfollowService, type: :service do
|
||||
let(:sender) { Fabricate(:account, username: 'alice') }
|
||||
|
||||
subject { UnfollowService.new }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UnmuteService do
|
||||
RSpec.describe UnmuteService, type: :service do
|
||||
subject { UnmuteService.new }
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UnsubscribeService do
|
||||
RSpec.describe UnsubscribeService, type: :service do
|
||||
let(:account) { Fabricate(:account, username: 'bob', domain: 'example.com', hub_url: 'http://hub.example.com') }
|
||||
subject { UnsubscribeService.new }
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UpdateRemoteProfileService do
|
||||
RSpec.describe UpdateRemoteProfileService, type: :service do
|
||||
let(:xml) { File.read(File.join(Rails.root, 'spec', 'fixtures', 'push', 'feed.atom')) }
|
||||
|
||||
subject { UpdateRemoteProfileService.new }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue