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

try_to_making_a_gem_with_pattern_matching.pdf

morihirok
October 16, 2019

 try_to_making_a_gem_with_pattern_matching.pdf

Ebisu.rb #25

morihirok

October 16, 2019
Tweet

More Decks by morihirok

Other Decks in Technology

Transcript

  1. Ruby2.7Ͱಋೖ͞ΕΔ
    Pattern matchingͰ
    GemΛ࡞ͬͯΈͨ
    Ebisu.rb #25
    @_morihirok

    View full-size slide

  2. About me
    • Github: morihirok
    • Twitter: @_morihirok
    • STORES.jp inc,

    View full-size slide

  3. Ruby 2.7ΑΓ
    Pattern matching
    ͱ͍͏ػೳ͕ೖΓ·͢

    View full-size slide

  4. 3VCZ,BJHJ1BUUFSONBUDIJOH/FXGFBUVSFJO3VCZΑΓҾ༻
    IUUQTTQFBLFSEFDLDPNL@UTKQBUUFSONBUDIJOHOFXGFBUVSFJOSVCZEPU

    View full-size slide

  5. 3VCZ,BJHJ1BUUFSONBUDIJOH/FXGFBUVSFJO3VCZΑΓҾ༻
    IUUQTTQFBLFSEFDLDPNL@UTKQBUUFSONBUDIJOHOFXGFBUVSFJOSVCZEPU

    View full-size slide

  6. ࢖ͬͯΈ͍ͨͷͰ
    Կ͔࡞Ζ͏

    View full-size slide

  7. STORES.jp͸ϝΠϯDB͕
    MongoDB
    • ओཁͳσʔλ͸શͯMongoDBʹೖ͍ͬͯΔ
    • ओཁͳΫΤϦ΋શͯMongoDBʹ޲͔͍ͬͯΔ
    • ౰વ࣮ߦܭը΋MongoDBͷ΋ͷΛ֬ೝ͢Δ
    • MongoDBͷexplain͸ಡΈͮΒ͍

    View full-size slide

  8. MongoDBͷexplain݁Ռͷ
    αϯϓϧ
    > db.items.find({price: 119}).explain("executionStats")
    {
    "queryPlanner" : {
    "plannerVersion" : 1,
    "namespace" : "sample_db.items",
    "indexFilterSet" : false,
    "parsedQuery" : {
    "price" : {
    "$eq" : 119
    }
    },
    "winningPlan" : {
    "stage" : "COLLSCAN",
    "filter" : {
    "price" : {
    "$eq" : 119
    }
    શͯ+40/Ͱදݱ͞ΕΔ

    View full-size slide

  9. Pattern matchingΛ࢖͑͹
    JSONͷѻ͍͕
    ָʹͳΔͷͰ͸ʁ

    View full-size slide

  10. ͱ͍͏͜ͱͰ࡞ͬͨͷ͕͜Ε
    FYQMBJOͷ+40/Λ
    ͍͍۩߹ʹ.BSLEPXOͷ
    ςʔϒϧʹม׵͢Δ

    View full-size slide

  11. ΠϯσοΫε͕ޮ͍ͯͳ͍ͱ͖ͷ
    explain݁Ռ
    ͕͜͜z$0--4$"/zʹͳΔ

    View full-size slide

  12. ͜͏ॻ͚Δ
    ͕͜͜z$0--4$"/zʹͳΔ

    View full-size slide

  13. ΠϯσοΫε͕ޮ͍͍ͯΔͱ͖ͷ
    explain݁Ռ
    ͕͜͜z'&5$)zʹมΘΔ
    ͕͜͜z*94$"/zʹͳΔ
    ͜͜ʹΠϯσοΫε໊͕ೖΔ

    View full-size slide

  14. ͜͏ॻ͚Δ
    ͕͜͜z'&5$)zʹมΘΔ
    ͕͜͜z*94$"/zʹͳΔ
    ͜͜ʹΠϯσοΫε໊͕ೖΔ

    View full-size slide

  15. ͜͏ॻ͚Δ
    ม਺ΛόΠϯυͰ͖Δ
    ͜͜ʹΠϯσοΫε໊͕ೖΔ

    View full-size slide

  16. ࠷ऴతʹ͸͜͏ͳΔ

    View full-size slide

  17. STORES.jpͰ΋
    ͍͍ײ͡ʹ࢖͑ͦ͏

    View full-size slide

  18. ͓લ͸ຊ൪ͷRubyΛ
    2.7ʹ্͛Δͭ΋Γͳͷ͔ʁ

    View full-size slide

  19. Pattern matchingແ͠Ͱ
    ॻ͖׵͑Δͱ

    View full-size slide

  20. Pattern matchingແ͠Ͱ
    ॻ͖׵͑Δͱ
    όʔδϣϯ͝ͱͷ
    ίʔυͷဃ཭͕ܹ͘͠ͳΔ

    View full-size slide

  21. ͜Μͳํ๏΋͋Γ·͢

    View full-size slide

  22. pattern-matchΛར༻͢Δͱ
    1SPDDBMM
    ͷγϯλοΫεγϡΨʔ͕

    Ͱ͋Δ͜ͱΛར༻͍ͯ͠Δ

    View full-size slide

  23. pattern-matchΛར༻͢Δͱ
    ͋Δఔ౓ࣅͨίʔυΛ
    อͭ͜ͱ͕Ͱ͖Δ

    View full-size slide

  24. Ruby2.7Ҏ্Ͱ͸
    Pattern matchingΛ࢖͍͍ͨ
    Ruby2.6ҎԼͰ΋
    gem͸࢖͍͍ͨ

    View full-size slide

  25. RubyͷόʔδϣϯʹΑͬͯ
    require͢ΔϑΝΠϧΛม͑Δ
    • mongo_clarify.rb
    3VCZͷόʔδϣϯʹΑͬͯ
    ϑΝΠϧΛม͍͑ͨϞδϡʔϧ

    View full-size slide

  26. RubyͷόʔδϣϯʹΑͬͯ
    require͢ΔϑΝΠϧΛม͑Δ
    • investigate.rb
    3VCZҎ্ͳΒ
    1BUUFSO.BUDIJOH൛Λ࢖͏

    View full-size slide

  27. • ىಈதͷRubyͷόʔδϣϯจࣈྻΛอ࣋͢Δ
    ఆ਺
    Gem::Version
    • όʔδϣϯจࣈྻΛൺֱՄೳʹ͢ΔΫϥε
    RUBY_VERSION

    View full-size slide

  28. ςετ΋RubyͷόʔδϣϯʹΑͬͯ
    require͢ΔϑΝΠϧΛม͑Δ
    • mongo_clarify_spec.rb
    3VCZͷόʔδϣϯʹΑͬͯ
    ϑΝΠϧΛม͍͑ͨϞδϡʔϧ

    View full-size slide

  29. ςετ΋RubyͷόʔδϣϯʹΑͬͯ
    require͢ΔϑΝΠϧΛม͑Δ
    • .travis.yml
    $*ʹෳ਺όʔδϣϯͰ
    ςετͯ͠΋Β͏

    View full-size slide

  30. RubyGemsʹస͕͍ͬͯ·͢
    • https://rubygems.org/gems/mongo_clarify

    View full-size slide

  31. ༨ஊ
    Gemͷ࡞੒աఔͰ
    MongoDBͷexplainʹ׳Ε
    ͜ͷGem࢖͍ͬͯͳ͍

    View full-size slide