post '/api/livestream/:livestream_id/livecomment' do
ボトルネックのコード
livecomment = db_transaction do |tx|
livestream_model = tx.xquery('SELECT id, user_id FROM livestreams WHERE id = ? LIMIT 1', livestream_id).first
unless livestream_model
raise HttpError.new(404, 'livestream not found')
end
# スパム判定
tx.xquery('SELECT id, user_id, livestream_id, word FROM ng_words WHERE user_id = ? AND livestream_id = ?', livestream_model.fetch(:user_id), livestream_model.fetch(:id)).each do |ng_word|
APIエンドポイント
post '/api/livestream/:livestream_id/livecomment' do
ボトルネックのコード
根拠
first なのでLimit1でよく idとuser_idしか使ってないので、それを減らす