taiwork / isucon13

0 stars 0 forks source link

[bottleneck]: first なのでLimit1でよく idとuser_idしか使ってないので、それを減らす #32

Closed taiwork closed 9 months ago

taiwork commented 9 months ago

APIエンドポイント

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|

根拠

first なのでLimit1でよく idとuser_idしか使ってないので、それを減らす