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

銀座Rails#1_uuushiro.pdf

uuushiro
September 20, 2018

 銀座Rails#1_uuushiro.pdf

uuushiro

September 20, 2018
Tweet

More Decks by uuushiro

Other Decks in Programming

Transcript

  1. Copyright © stmn, inc. All rights reserved. Page !X ࣗݾ঺հ

    ϋϯυϧωʔϜ/ࢯ໊ @uuushiro / দ୩ ༐࢙࿕(·ͭͨʹ Ώ͏͠Ζ͏) 
 ग़਎
 ɹѪ஌ݝ ඌுѴࢢ (ݱॅॴ͸໊ݹ԰ࢢ)
 ੜ೥݄೔
 ɹ1994/02/01 (24ࡀ)
 ུྺ ɹ2016೥ 9݄ ελϝϯͰΠϯλʔϯ։࢝ ɹ2017೥ 1݄ ελϝϯʹೖࣾ (৽ଔୈҰ߸) Rails ver 5.0.0 ͔Β৮Γ·ͨ͠ Raisྺ2೥
  2. Copyright © stmn, inc. All rights reserved. Page Ԋֵͱࣾһ਺ !4

    ໊ ձһ਺ ࣾһ਺ ૑ۀ 56/"( ЌϦϦʔε ౦ژࢧࣾ ࢿۚௐୡ ԯԁ 56/"( ਖ਼ࣜϦϦʔε ໊ݹ԰ຊࣾ ΦϑΟεҠస େࡕࢧࣾ 3BJMT   3VCZ 
  3. Copyright © stmn, inc. All rights reserved. Page ػೳ •

    λΠϜϥΠϯɺϓϩϑΟʔϧɺνϟοτ Λඋ͑ͨɺϑϧػೳͷSNSɻ͢΂ͯࣗࣾ։ൃɻ • ೚ҙͷ੍౓(౤ߘϑΥʔϜ)Λ࡞Δ͜ͱ͕Ͱ͖Δ (Google ϑΥʔϜ ͷߴػೳ൛)ɻ !9 גࣜձࣾελϝϯͰͷར༻෩ܠ
  4. Copyright © stmn, inc. All rights reserved. Page TUNAGͷٕज़ελοΫ !10

    /BUJWF 'SPOUFOE "QQMJDBUJPO .JEEMFXBSF *OGSBTUSVDUVSF .FUBCBT
  5. Copyright © stmn, inc. All rights reserved. Page TUNAGͷٕज़ελοΫ !11

    /BUJWF 'SPOUFOE "QQMJDBUJPO .JEEMFXBSF *OGSBTUSVDUVSF .FUBCBT ੈͷதͷศརͳαʔϏε͸ੵۃతʹར༻͠ɺ ࣗࣾͷڧΈʹूத͍ͨ͠
  6. Copyright © stmn, inc. All rights reserved. Page ໨࣍ •ೖΕͯΑ͔ͬͨgem

    •࢖ͬͯΑ͔ͬͨπʔϧɾαʔϏε •औΓೖΕͯΑ͔ͬͨ։ൃελΠϧ !13
  7. Copyright © stmn, inc. All rights reserved. Page aasm !15

    ঢ়ଶભҠ؅ཧΛαϙʔτͯ͘͠ΕΔgem
  8. Copyright © stmn, inc. All rights reserved. Page ෳࡶͳঢ়ଶભҠ͸؅ཧ͕೉͍͠ •TUNAGͰ͸Ϟσϧͷঢ়ଶ؅ཧ͸

    enum Ͱ؅ཧ͍ͯ͠Δ •ঢ়ଶભҠ͕ෳࡶԽ͢Δͱ؅ཧ͕େม •᜛ٞͷΑ͏ͳঝೝػೳ(ϫʔΫϑϩʔ) ΍ ECͷ஫จ؅ཧͳͲ !16 ։࢝ Ωϟϯηϧ ਃ੥த ঝೝࡁΈ ׬ྃ ٫Լ
  9. Copyright © stmn, inc. All rights reserved. Page aasmͷಛ௃ •DSLͰঢ়ଶભҠͷ੍໿Λ؆ܿʹهड़Ͱ͖Δ

    •ঢ়ଶભҠ࣌ʹ೚ҙͷίʔϧόοΫΛࢦఆͰ͖Δ •enum ͕ར༻Ͱ͖Δ •σϑΥϧτͩͱ aasm_state ΧϥϜΛ௥Ճ͢Δ !17
  10. Copyright © stmn, inc. All rights reserved. Page ίʔυྫ !18

    Մಡੑ͕ߴ͘ɺ ঢ়ଶભҠͷ੍໿Λ؅ཧ͠΍͍͢
  11. Copyright © stmn, inc. All rights reserved. Page ίʔυྫ !19

    Մಡੑ͕ߴ͘ɺ ঢ়ଶભҠͷ੍໿Λ؅ཧ͠΍͍͢ ಛఆͷঢ়ଶભҠͷίʔϧόοΫͷࢦఆ ͢΂ͯͷঢ়ଶભҠͷίʔϧόοΫࢦఆ FOVNར༻Մ
  12. Copyright © stmn, inc. All rights reserved. Page railroadyͱ૊Έ߹ΘͤΔͱ΋ͬͱخ͍͠ •ঢ়ଶભҠਤΛ࡞੒ͯ͘͠ΕΔ

    !20 CVOEMFFYFDSBJMSPBEZ"TQFDJGZBQQNPEFMTNPEFMSCcEPU5QOHP 3"*-4@3005EPDTUBUF@DIBOHFTNPEFMQOH
  13. Copyright © stmn, inc. All rights reserved. Page RDBͰπϦʔߏ଄Λ࣮ݱ͍ͨ͠ •اۀ޲͚SNSͰ͸ɺ૊৫ਤ

    Λ ࣮૷͢Δඞཁ͕͋Δ •ྡ઀ϦετϞσϧ • ௚ۙͷ਌ͷΈΛࢀর • ΞϓϦέʔγϣϯଆͰ࠶ؼॲཧ •ܦ࿏ྻڍϞσϧ • ֎෦Ωʔ੍໿͕࢖͑ͳ͍ͨΊRDBͰ਌ࢠؔ܎ͷ੔߹ੑ͕อূͰ͖ͳ͍ •ೖΕࢠू߹Ϟσϧ !22 ͸͡Ί͸͜ΕΛ࠾༻͍ͯͨ͠
  14. Copyright © stmn, inc. All rights reserved. Page TUNAGʹ͓͚ΔπϦʔߏ଄ͷཁ݅ •πϦʔߏ଄ΛͨͲΔॲཧ͕ଟ͍

    •૊৫ ΍ ഑ଐ ͷߋ৽ස౓͸গͳ͍ •awesome_nested_set (ೖΕࢠू߹Ϟσϧ)Λ࠾༻ •ߋ৽ίετ͸ߴ͍͕ɺۙ઀ϦετϞσϧͱൺ΂ͯΫΤϦ਺Λ཈੍Ͱ͖Δ •left, rightΧϥϜ͚ͩͰͳ͘ɺparent_id΋࣋ͨͤΔͷͰɺࢠͷݕࡧޮ཰্͕͕Δ !23
  15. Copyright © stmn, inc. All rights reserved. Page elasticsearch-model &

    elasticsearch-dsl !25 ElasticsearchΛRailsͰѻ͍΍͘͢͢Δgem
  16. Copyright © stmn, inc. All rights reserved. Page elasticsearch-model •ϞσϧͱElasticsearchͷ౷߹Λิॿ

    •searchϝιουͱimportϝιου͕ఆٛ͞ΕΔ •as_indexed_jsonΛΦʔόʔϥΠυ͢Δ͜ͱͰɺ import࣌ʹ࣮ߦ͞ΕΔσʔλͷม׵ ΛίϯτϩʔϧͰ͖Δ •ؔ࿈ςʔϒϧͷࢦఆ΋؆୯ʹ !26
  17. Copyright © stmn, inc. All rights reserved. Page elasticsearch-dsl •ΫΤϦΛDSLͰهड़Ͱ͖Δ

    •ؔ࿈͢Δෳ਺ͷϞσϧΛର৅ͱͨ͠ɺෳࡶͳݕࡧ͕Ͱ͖Δ •must: AND৚݅ •filter: AND৚݅ •should: OR৚݅ •must_not: NOT৚݅ !27
  18. Copyright © stmn, inc. All rights reserved. Page Alias Λར༻ͨ͠

    ΠϯσοΫεͷ࠶ߏங •ΠϯσοΫεʹΤΠϦΞε໊Λ෇༩͢Δ͜ͱ͕Ͱ͖Δɻ •ΤΠϦΞεͷࢀরઌΛ੾Γସ͑Δ͜ͱͰɺΠϯσοΫεΛೖΕସ͑Δ͜ͱ͕Ͱ͖Δɻ •ΤΠϦΞεͷ੾Γସ͑͸ɺΞτϛοΫʹߦΘΕΔ͜ͱ͕อূ͞Ε͍ͯΔɻ !28
  19. Copyright © stmn, inc. All rights reserved. Page xray-rails !29

    ϒϥ΢β্Ͱviewͷߏ଄ΛՄࢹԽͯ͘͠ΕΔ
  20. Copyright © stmn, inc. All rights reserved. Page !31 ΫϦοΫ͢Δͱ

    ΤσΟλͰ֘౰ύʔγϟϧ Λ։͍ͯ͘ΕΔ ؔ࿈͢Δ$POUSPMMFS ΤσΟλͷઃఆ 3BJMTSPPUYSBZDPOpHΤσΟλઃఆϑΝΠϧ FEJUPS"QQMJDBUJPOT3VCZ.JOFBQQ$POUFOUT.BD04SVCZNJOFpMF
  21. Copyright © stmn, inc. All rights reserved. Page ඇಉظॲཧ: DelayedJob

    & Sidekiq •DelayedJob •Job ͕ DB Ͱ؅ཧ͞ΕΔͨΊɺModel ͷτϥϯβΫγϣϯʹ࿈ಈͤ͞Δ͜ͱ͕Ͱ͖Δɻ • assm ͱ૊Έ߹Θͤͯɺঢ়ଶભҠ ʹ࿈ಈͨ͠ඇಉظॲཧʹར༻͍ͯ͠Δɻ •Polling ͳͷͰଈԠੑ͸ແ͍ •DBͷΈͰ׬݁Ͱ͖Δ •sidekiq •ΠϕϯτυϦϒϯͰߴ଎ •PUSH௨஌ͷҰ੪ૹ৴ͳͲ୹ظؒͰେྔͷδϣϒΛࡹ͚Δ •redis ͕ඞཁ !32
  22. Copyright © stmn, inc. All rights reserved. Page imgix(ը૾ઐ༻CDN) •ը૾഑৴ઐ༻ͷCDNɻ

    •AWS S3 ্ͷը૾ΛϦΞϧλΠϜʹՃ޻͠ͳ͕Βɺߴ଎഑৴Ͱ͖Δɻ •΋ͱ΋ͱ͸ɺRails (ImageMagick) Ͱ Ճ޻͠ AWS CloudFront Ͱ഑৴͍ͯͨ͠ɻ •ॳճΞΫηε͕ಉ࣌ฒߦʹߦΘΕΔͱϨεϙϯε͕ѱԽ͢Δ͜ͱ͕͋ͬͨ •اۀ޲͚SNSͱ͍͏ಛੑ্ɺಋೖॳ೔ͳͲʹΞΫηε਺͕ूத͠ɺ
 ϨεϙϯελΠϜ͕ѱԽ͢Δ͜ͱ͕͋ͬͨ •imgixΛಋೖ͢Δ͜ͱͰɺWEBαʔόͷෛՙΛ΁Β͢͜ͱ͕Ͱ͖ɺ͞ΒʹαΠτεϐʔυ΋޲্ͨ͠ •small_light ͳͲͰը૾഑৴αʔόΛߏங͢ΔΑΓ΋͍҆͠ɺ଎͔ͬͨ •إݕग़ػೳͳͲɺػೳ΋͍͍ ײ͡ɻ !34
  23. Copyright © stmn, inc. All rights reserved. Page Bugsnag(ΫϥογϡϨϙʔτղੳπʔϧ) !37

    EFWJTFΛ࢖͍ͬͯΔͱɺ ݱࡏೝূ͞Ε͍ͯΔϢʔβʔʹؔ͢Δ৘ใΛ ࣗಈతʹऔಘͯ͘͠ΕΔ
  24. Copyright © stmn, inc. All rights reserved. Page Bugsnag(ΫϥογϡϨϙʔτղੳπʔϧ) !40

    $POUSPMMFSɺϗετ໊ɺϦΫΤετ63-ɺϦΫΤετ*1ͰߜΓࠐΊΔ
  25. Copyright © stmn, inc. All rights reserved. Page SendGrid •ό΢ϯεॲཧΛ࣮૷͠ͳͯ͘΋ྑ͍ɻ

    •ϝʔϧαʔόʔΛ༻ҙ͠ͳͯ͘ࡁΉ •։෧཰ɺΫϦοΫ཰Λ೚ҙͷ୯ҐͰऔಘͰ͖Δ •sendgrid-rubyͰAPIΛར༻͕؆୯ʹ !41
  26. Copyright © stmn, inc. All rights reserved. Page Metabase(BIπʔϧ) !44

    (6*Ͱϙνϙν͢Δ͚ͩ͋Δఔ౓ͷ ΫΤϦ͸ߏஙͰ͖Δ
  27. Copyright © stmn, inc. All rights reserved. Page Metabase(BIπʔϧ) !45

    (6*Ͱϙνϙν͢Δ͚ͩ͋Δఔ౓ͷ ΫΤϦ͸ߏஙͰ͖Δ 440ʹ΋ରԠ͍ͯ͠Δ
  28. Copyright © stmn, inc. All rights reserved. Page ఆظbundle update

    •Rails ͷ ਐԽʹ͍͍ͭͯ͘͜ͱ͕໨తɻ •ӨڹൣғΛಛఆ͠΍͘͢ɺݕূίετΛখ͘͢͞ΔͨΊʹɺि࣍ͰΞοϓσʔτɻ •ར༻͍ͯ͠Δgem΁ͷཧղΛਂΊΒΕΔ •CircleCI 2.0ͷϫʔΫϑϩʔػೳͰࣗಈԽ !47
  29. Copyright © stmn, inc. All rights reserved. Page ϨϏϡʔͷࣗಈԽ •ίʔσΟϯάελΠϧͳͲఆܕͳνΣοΫ͸ࣗಈԽ͢Δɻ

    •ઃܭ΍ΞϓϦέʔγϣϯϩδοΫͷϨϏϡʔʹ࣌ؒΛ͔͚Δɻ •rubocop, SiderΛಋೖ !48
  30. Copyright © stmn, inc. All rights reserved. Page RailsελʔτΞοϓ͕΍ͬͯΑ͔ͬͨ͜ͱ !49

    ೖΕͯྑ͔ͬͨHFN BBTN BXFTPNF@OFTUFE@USFF FMBTUJDTFBSDINPEFM FMBTUJDTFBSDIETM YSBZSBJMT EFMBZFE@KPC 4JEFLJR ೖΕͯྑ͔ͬͨπʔϧɾαʔϏε JNHJY #VHTOBH 4FOE(SJE .BJMUSBQ .FUBCBTF औΓೖΕͯྑ͔ͬͨ։ൃελΠϧ ఆظCVOEMFVQEBUF ϨϏϡʔͷࣗಈԽ