Skip to content

Instantly share code, notes, and snippets.

@abcang
Created September 26, 2017 14:39
Show Gist options
  • Save abcang/1db9d5307cd25dee63c655c4b8b041c9 to your computer and use it in GitHub Desktop.
Save abcang/1db9d5307cd25dee63c655c4b8b041c9 to your computer and use it in GitHub Desktop.
PawooでDMを送ったときのInboxesControllerの様子
| 1 | # frozen_string_literal: true
| 2 |
| 3 | class ActivityPub::InboxesController < Api::BaseController
| 4 | include SignatureVerification
| 5 |
| 6 | before_action :set_account
| 7 |
| 8 | def create
18 (15.3%) | 9 | if signed_request_account
1 (0.8%) | 10 | upgrade_account
9 (7.6%) | 11 | process_payload
2 (1.7%) | 12 | head 201
| 13 | else
| 14 | head 202
| 15 | end
| 16 | end
| 17 |
| 18 | private
| 19 |
| 20 | def set_account
31 (26.3%) | 21 | @account = Account.find_local!(params[:account_username]) if params[:account_username]
| 22 | end
| 23 |
| 24 | def body
| 25 | @body ||= request.body.read
| 26 | end
| 27 |
| 28 | def upgrade_account
1 (0.8%) | 29 | if signed_request_account.ostatus?
| 30 | signed_request_account.update(last_webfingered_at: nil)
| 31 | ResolveRemoteAccountWorker.perform_async(signed_request_account.acct)
| 32 | end
| 33 |
| 34 | Pubsubhubbub::UnsubscribeWorker.perform_async(signed_request_account.id) if signed_request_account.subscribed?
| 35 | end
| 36 |
| 37 | def process_payload
9 (7.6%) | 38 | ActivityPub::ProcessingWorker.perform_async(signed_request_account.id, body.force_encoding('UTF-8'))
| 39 | end
| 40 | end
@abcang
Copy link
Author

abcang commented Sep 26, 2017

use StackProf::Middleware,
    enabled: ENV['ENABLE_STACKPROF'].to_i.nonzero?,
    mode: :wall,
    interval: 100,
    save_every: 1,
    path: 'tmp/stackprof'

intervalが100なので、左側の数字は1あたりだいたい0.1ミリ秒です
Account.find_local!が3ミリ秒かかってるのはだいたい合ってそう

irb(main):004:0> result = Benchmark.realtime do
irb(main):005:1* Account.find_local!('abcang')
irb(main):006:1> end
  Account Load (0.9ms)  SELECT  "accounts".* FROM "accounts" WHERE (NOT (("accounts"."username" = '' OR "accounts"."username" IS NULL))) AND LOWER("accounts"."username") = 'abcang' AND "accounts"."domain" IS NULL LIMIT $1  [["LIMIT", 1]]
=> 0.003574470989406109

ActivityPub::InboxesControllerが遅いとは思えない

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment