Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ハマったところ 表参道.rb #44 / into a problem

ハマったところ 表参道.rb #44 / into a problem

Railsアプリ運用時にハマったときの体験です

Keiji Matsuzaki

March 07, 2019
Tweet

More Decks by Keiji Matsuzaki

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • Piece of Cake, Inc. • দ࡚ ܒ࣏ (·͖ͭ͟

    ͚͍͡) • αʔόαΠυ݉ΠϯϑϥΤϯδχΞ • 2019೥1݄͔Β
  2. uniq • ͖͔͚ͬRails 4.2 -> 5.1΁ͷΞοϓάϨʔυ͕࠷ॳͷ࢓ࣄ • deprecated 5.0 ->

    5.1ΑΓ • distinctʹॻ͖׵͑Δඞཁ͕͋Δ • uniqΛ͋Δఔ౓ݕࡧ͍͕ͯͨ͠ɺͱ͋ΔՕॴͰॻ͖׵͑ ࿙Ε͕͋ͬͨ
  3. ଞ (աڈͷܦݧ) • INDEXΛࢥͬͨΑ͏ʹ࢖ͬͯ͘Ε͍ͯͳ͍͜ͱ͕Θ͔ͬͨ ͷͰɺFORCE INDEXΛ࢖͏Α͏ʹվળ͢Δ • SELECT … FOR

    UPDATE Λൃߦதɺ͏͔ͬΓtransaction block಺ʹ ଞαʔϏε ΁ͷAPIΞΫηεΛߦ͏ॲཧΛೖΕͯ ͠·͏ • ଞαʔϏεͷϦΫΤετॲཧʹࣦഊ͠ߦLOCKΛѲͬͨ· ·ʹͳΓঃʑʹϦΫΤετʹ٧·͍ͬͯ͘ͳͲ
  4. ࢀߟ • ActiveRecord::Relation distinct method (Rails 4.2) • https://github.com/rails/rails/blob/v4.2.11/activerecord/ lib/active_record/relation/query_methods.rb#L776

    • ActiveRecord::Relation (Rails 5.1) -> include Enumerable • https://github.com/rails/rails/blob/v5.1.6.1/activerecord/ lib/active_record/relation.rb