Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
とあるプロジェクトでコードを書き始めた僕がつまづいた石たち
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
zaru
April 05, 2019
Technology
200
0
Share
とあるプロジェクトでコードを書き始めた僕がつまづいた石たち
zaru
April 05, 2019
More Decks by zaru
See All by zaru
Next.js App Router セキュリティ
zaru_sakuraba
21
8.5k
Hotwire を 本番環境で使ってみた感想
zaru_sakuraba
7
6.7k
失敗から学ぶ個人開発
zaru_sakuraba
18
5.6k
伝わらない Issue の書き方
zaru_sakuraba
1
900
Ruby との対話 : pry を使い pry をデバッグし pry のバグを直す話
zaru_sakuraba
4
610
もう「クレデンシャルください」なんて言わせない
zaru_sakuraba
5
1.6k
個人プロジェクト現状報告会
zaru_sakuraba
0
150
僕と契約して、メソッドになってよ!
zaru_sakuraba
0
200
Other Decks in Technology
See All in Technology
Chasing Real-Time Observability for CRuby
whitegreen
0
120
QGISプラグイン CMChangeDetector
naokimuroki
1
400
EBS暗号化に失敗してEC2が動かなくなった話
hamaguchimmm
2
200
国内外の生成AIセキュリティの最新動向 & AIガードレール製品「chakoshi」のご紹介 / Latest Trends in Generative AI Security (Domestic & International) & Introduction to AI Guardrail Product "chakoshi"
nttcom
3
1k
20260423_執筆の工夫と裏側 技術書の企画から刊行まで / From the planning to the publication of technical book
nash_efp
3
400
20260428_Product Management Summit_Loglass_JoeHirose
loglassjoe
0
1.4k
はじめての MagicPod生成AI機能 機能紹介から活用方法まで
magicpod
0
100
生成AIが変える SaaS の競争原理と弁護士ドットコムのプロダクト戦略
bengo4com
0
850
Claude Code を安全に使おう勉強会 / Claude Code Security Basics
masahirokawahara
11
33k
コミュニティ・勉強会を作るのは目的じゃない
ohmori_yusuke
0
210
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
16k
ハーネスエンジニアリングをやりすぎた話 ~そのハーネスは解体された~
gotalab555
4
1.7k
Featured
See All Featured
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
100
Technical Leadership for Architectural Decision Making
baasie
3
330
sira's awesome portfolio website redesign presentation
elsirapls
0
220
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
320
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
64
55k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
310
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
520
Faster Mobile Websites
deanohume
310
31k
Transcript
とあるプロジェクトで コードを書き始めた僕が つまづいた石たち 2019.04.05 TGIF @zaru
site = Site.find site_id
いたるところにある Site.find id | Site.find name … site.name というのは c1234567890
のような識別子
まさかの find を override していた def find id any_of({_id: id},
{name: id}).first end id もしくは name どちらでもヒットする 気持ちはわかるけど検索キーはどちらかに統一したほうが良い なぜならアプリケーション全体で id と name どちらで持ち回るのか が曖昧になる。ここで透過的に処理するのではなく、もう少し手前 で透過的な処理をしたほうが良い 例外出すと信じてたのに…
site = Site.find site_id
特定ドキュメントの場合、とにかく遅い 大量にある embeds_many が原因 ferret One サービスサイトだと 5MB 以上ある fetch
するのに 200-300msec くらいかかってた Site.without(:hoge) や Site.only(:piyo) でスリムに 20-30msec くらいに改善 embeds_many -> has_many にしたい
Site.without(:hoge).find
mongoid の仕様で一部のフィールドのみを取得した場合は save でき ない set で直接書き換えるしかない… site = Site.without(:hoge).first
site.title = 'update' site.save # NG site.set(title: 'update') # OK これは今後しんどくなりそうな雰囲気を感じている ActiveRecord ってどうだったっけ… ?
response = RestClient.get(query_images)
これ自体はなんてことはない普通のコード rest-client という gem を使っている ただし Gem le には rest-client
は存在しない mailjet というメール配信の gem が rest-client に依存 それを利用している… しかし mailjet はもう使っていないので gem を削除すると死ぬ そして faraday という別の HTTP クライアント gem がありバッティ ングしている
resources :hoge
resources :hoge ← 全部 action あるのかな? 実は使っているのは update だけでした only
except を使った方が良い
# TODO: これは使われているのか… ?
テストコードやリファクタをする際に、メソッドが使われているの か使われていないのかが、すぐ判断できなかった そのメソッドに依存したコードが山のようにあるし URL も露出し ている lograge -> redash があったので実際に
call されているかどうかで判 断 使わなくなったコードはすぐに削除しましょう
TemporaryPage.find(1).site_id
Site has_many Page TemporaryPage extends Page temporary_page.site #=> <Site ....>
temporary_page.site_id #=> nil リレーションしているのだからあるはずでは… ? def site で定義されていた… def site self.public_page.try(:site) end
どんどん良くしていくぞ! という気持ち