Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
とあるプロジェクトでコードを書き始めた僕がつまづいた石たち
Search
zaru
April 05, 2019
Technology
220
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
とあるプロジェクトでコードを書き始めた僕がつまづいた石たち
zaru
April 05, 2019
More Decks by zaru
See All by zaru
Next.js App Router セキュリティ
zaru_sakuraba
22
8.9k
Hotwire を 本番環境で使ってみた感想
zaru_sakuraba
7
6.9k
失敗から学ぶ個人開発
zaru_sakuraba
18
5.6k
伝わらない Issue の書き方
zaru_sakuraba
1
1.4k
Ruby との対話 : pry を使い pry をデバッグし pry のバグを直す話
zaru_sakuraba
4
650
もう「クレデンシャルください」なんて言わせない
zaru_sakuraba
5
1.7k
個人プロジェクト現状報告会
zaru_sakuraba
0
170
僕と契約して、メソッドになってよ!
zaru_sakuraba
0
230
Other Decks in Technology
See All in Technology
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
1
380
LLM Content Moderationを支える評価・改善ループの実践
suikabar
2
290
[JAWS-UG彩の国埼玉#12]そろそろ準備する?re:Invent2026をやさしく解説 / reinvent2026-sainokuni
sh_fk2
1
380
freeeにおける AI を用いた ブラウザ動作確認の自動化の取り組み
freee
PRO
0
110
ウォンテッドリーの最近のプロダクトと技術の紹介
stomk
0
320
オントロジーって 結局なにもの? AI エージェントに「意味」を渡す知識設計の話
greenmidori
0
250
10年後、Engineering 行為を剥奪されるとして、わたしたちは、どう、何を創ればいいだろうか。 / If Engineering Is Taken Away in 10 Years, How and What Should We Create?
bitkey
PRO
1
220
【データ横丁主催】AI エージェント時代のTranslytical Data Platform
shisyu_gaku
0
200
Post AI時代のリファクタリング実践記 / Refactoring in the post AI era
kaminashi
1
320
Classmethod Company Deck
satoshi7
1
800
価値について
gree_tech
PRO
0
140
Kiro Crewで「みのるん式」仕事術やってみた
minorun365
PRO
3
990
Featured
See All Featured
The Language of Interfaces
destraynor
162
27k
How STYLIGHT went responsive
nonsquared
100
6.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Utilizing Notion as your number one productivity tool
mfonobong
4
620
Facilitating Awesome Meetings
lara
57
7.2k
Git: the NoSQL Database
bkeepers
PRO
433
67k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Believing is Seeing
oripsolob
1
250
The SEO identity crisis: Don't let AI make you average
varn
0
590
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
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
どんどん良くしていくぞ! という気持ち