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

大規模 Padrino アプリケーション Rails 移行 / Migrating to Ra...

大規模 Padrino アプリケーション Rails 移行 / Migrating to Rails from Padrino

Tsukuru Tanimichi

April 26, 2016
Tweet

More Decks by Tsukuru Tanimichi

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • @ttanimichi • 2014೥6݄ʙ גࣜձࣾ Aiming • ڞ௨ج൫ͷ։ൃΛ͍ͯͨ͠ •

    ࠷ۙήʔϜλΠτϧʹҟಈ • https://github.com/ttanimichi • [email protected] (C) Tsukuru Tanimichi, 2016 2
  2. ؀ڥ • Ruby 2.0 • Padrino 0.11 • MySQL 5.5

    • nginx • Redis (C) Tsukuru Tanimichi, 2016 4
  3. rake stats % bin/rake stats +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines

    | LOC | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Controllers | 2984 | 2566 | 50 | 302 | 6 | 6 | | Helpers | 86 | 86 | 0 | 1 | 0 | 84 | | Models | 15810 | 13029 | 422 | 1513 | 3 | 6 | | Mailers | 0 | 0 | 0 | 0 | 0 | 0 | | Javascripts | 11577 | 7916 | 1 | 809 | 809 | 7 | | Libraries | 19329 | 13621 | 693 | 1754 | 2 | 5 | | Controller specs | 223 | 181 | 0 | 2 | 0 | 88 | | Lib specs | 4404 | 3603 | 6 | 6 | 1 | 598 | | Model specs | 31852 | 26255 | 0 | 19 | 0 | 1379 | | Request specs | 15 | 13 | 0 | 0 | 0 | 0 | | Service specs | 24027 | 19808 | 3 | 37 | 12 | 533 | +----------------------+-------+-------+---------+---------+-----+-------+ | Total | 110307 | 87078 | 1175 | 4443 | 3 | 17 | +----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 37218 Test LOC: 49860 Code to Test Ratio: 1:1.3 (C) Tsukuru Tanimichi, 2016 5
  4. rake stats % bin/rake stats +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines

    | LOC | Classes | Methods | M/C | LOC/M | ... | Models | 15810 | 13029 | 422 | 1513 | 3 | 6 | ... +----------------------+-------+-------+---------+---------+-----+-------+ 400 Models (C) Tsukuru Tanimichi, 2016 6
  5. rake stats • COOKPAD Ͱ 1500 Models • lib/ ҎԼʹ΋

    Model ͬΆ͍Ϋϥε͕100ݸ͘ Β͍͋ͬͨ • ͋ΘͤΔͱ 500 Models ͘Β͍ • COOKPAD ͷ 1/3 ͘Β͍ʁʁ (C) Tsukuru Tanimichi, 2016 8
  6. ͭΒΈ • rake spec ʹ1͔͔࣌ؒΔ • autoload ࢖ͬͯͳ͔ͬͨ • ىಈʹ2෼͘Β͍͔͔Δ

    • spec Ұ࣮݅ߦ͢Δ͚ͩͰ΋2෼ • AR ͷΩϟογϡ͕ޮ͍ͯͳ͍ͬΆ͍ʁʁ (C) Tsukuru Tanimichi, 2016 10
  7. Ҡߦίετ • Padrino ͔Β Rails ΁ͷҠߦ • activerecord ͷόʔδϣϯΛ্͛Δ •

    activesupport ͷόʔδϣϯΛ্͛Δ • ͍ͭͰʹ Ruby ͷόʔδϣϯ΋্͛Δ (C) Tsukuru Tanimichi, 2016 15
  8. ํ਑ • ·ͣ͸ Rails4 Ͱಈ͔͢͜ͱ͚ͩߟ͑Δ • ʮ͍ͭͰʹϦϑΝΫλϦϯάʯ͸ೝΊͳ͍ • ػցతʹҠߦ࡞ۀ͚ͩ͢Δ •

    ϦϑΝΫλϦϯά΍ࡉ͔͍վળ͸Ҡߦޙʹ͍͘ ΒͰ΋Ͱ͖Δ (C) Tsukuru Tanimichi, 2016 16
  9. ํ਑ • Rails΁ͷҠߦͱ͍͏ʮେ͖͍໰୊ʯ • ಉ࣌ʹϦϑΝΫλϦϯά΋͠͸͡ΊΔͱӬ ԕʹҠߦ࡞ۀ͕׬ྃ͠ͳ͍ • Ϗδωεଆ͕ΩϨΔ → Ҡߦ͕ࣦഊ

    • ͱʹ͔͘ػցతʹҠߦ͢Δ • Կ΋ߟ͑ͣʹ spec ͕ίέ͍ͯΔॴΛ௚͢ (C) Tsukuru Tanimichi, 2016 17
  10. Ҡߦखॱ • ͱʹ͔͘·ͣ͸σΟϨΫτϦߏ଄Λ࡞Δ • Padrino ଆ͔Β Models ͳͲΛҠ͍ͯ͘͠ • bundle

    exec rspec ͕ಈ͘ͱ͜Ζ·Ͱ͸Ұਓ Ͱ΋ͬͯ͘ • rails new • rails generate rspec:install • database.yml ͷઃఆͱ͔ (C) Tsukuru Tanimichi, 2016 18
  11. bundle exec rspec ಈ͍ͨ • ͔͜͜Βઌ͸ϝϯόʔʹ࡞ۀΛৼΔ • ͱʹ͔͘ spec ͑͞ಈ͚͹෼ۀͰ͖Δ

    • ෼୲ͯ͠ spec ͕ίέ͍ͯΔ෦෼Λमਖ਼ (C) Tsukuru Tanimichi, 2016 21
  12. ੝େʹίέΔ spec • ͲΜ͚ͩίέͯͯ΋ spec ͕ಈ͖͑͢͞Ε͹म ਖ਼͸ϝϯόʔʹ෼୲Ͱ͖Δ • Active Record

    3 ͱ 4 ͷඇޓ׵ͱ͔ • ઃఆ·ΘΓͷ໰୊ • padrino helper ΁ͷґଘ • ಉ໊͡લͷϝιουΛఆٛͯ͠ rails ͷ helper ΁ΞΫηε͢ΔΑ͏मਖ਼ (C) Tsukuru Tanimichi, 2016 24
  13. Ͱ͖·ͨ͠ % rails -v Rails 4.2.4 % ruby -v ruby

    2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14] ຊ൪؀ڥͰطʹಈ͍ͯ·͢ (C) Tsukuru Tanimichi, 2016 25
  14. ؅ཧը໘ • ຊମͱ؅ཧը໘͸ผΞϓϦέʔγϣϯ • ؅ཧπʔϧଆ͸ຊମଆͷ Model Λࢀর • ؅ཧπʔϧଆ͸Ұ୴ Padrino

    ͷ··࢒ͨ͠ • Ұ෦ͷ Model ͕ Rails.env ʹґଘʢྑ͘ͳ͍ʣ • Padrino ͷ৔߹͸ Padrino.env Λࢀর͍ͨ͠ (C) Tsukuru Tanimichi, 2016 30
  15. Rails = Padrino ΩλίϨ Rails = Padrino Rails.env #=> "development"

    ॳظԽ࣌ʹ Rails ͱ͍͏ఆ਺Λఆٛ ※ ωλͰ͢ ※ ؅ཧը໘΋ Rails ΁ͷҠߦ࡞ۀΛࠓ͍ͯ͠ΔΑ ※ ؅ཧը໘ͷ Rails Ҡߦ΋΄ͱΜͲ׬ྃ (C) Tsukuru Tanimichi, 2016 31