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

Eight with Ruby

Sansan
November 02, 2018

Eight with Ruby

■イベント
RubyWorld Conference 2018
https://2018.rubyworld-conf.org/

■講演概要
タイトル:Eight with Ruby
登壇者:鈴木 康寛(Sansan株式会社)
https://2018.rubyworld-conf.org/program/

▼Sansan Builders Box
https://buildersbox.corp-sansan.com/

Sansan

November 02, 2018
Tweet

More Decks by Sansan

Other Decks in Technology

Transcript

  1. Creating a resource from everyday business
 encounters and transforming
 the

    way the world works. Ϗδωεͷग़ձ͍Λ ɹࢿ࢈ʹม͑ɺ
 ಇ͖ํΛֵ৽͢Δ
  2. Eightʹ͍ͭͯ - ໊ࢗ؅ཧ - ໊ࢗΛࡱΔ͚ͩͰਖ਼֬ʹσʔλԽ - ϏδωεωοτϫʔΫ - ໊ࢗަ׵͔Β޿͕ΔωοτϫʔΫ -

    اۀͱ΋࿈ܞ - Ϗδωείϛϡχέʔγϣϯ - ϑΟʔυ - ϝοηʔδ - ΞϓϦͰ໊ࢗަ׵
  3. ϑΟʔυػೳͷΞʔΩςΫνϟ࡮৽ - Amazon Aurora + Redis - Active Record, Rails.cacheͱͷ૬ੑ͕͍͍

    - ΩϟογϡʹΑΔಡΈࠐΈߴ଎Խ - Rails wayͰίʔυΛγϯϓϧʹ
  4. ϑΟʔυػೳͷΞʔΩςΫνϟ࡮৽ class User < ApplicationRecord def fetch_feed cache_keys = redis.zrevrange(cache_key,

    0, -1).map { |id| Post.cache_key_for(id: id) } return fetch_read_feed unless cache_keys.any? # Fall back to slow feed if there is no cache Rails.cache.fetch_multi(*cache_keys, expires: 1.minute, race_condition_ttl: 5.seconds) do |key| id = Post.id_from_cache_key(key: key) Post.find_by(id: id) end.values end def fetch_read_feed Post.eager_load(:user) .where(user: self.following + [self]) .order('posts.created_at DESC') end end