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
0
180
とあるプロジェクトでコードを書き始めた僕がつまづいた石たち
zaru
April 05, 2019
Tweet
Share
More Decks by zaru
See All by zaru
Next.js App Router セキュリティ
zaru_sakuraba
20
8.3k
Hotwire を 本番環境で使ってみた感想
zaru_sakuraba
7
6.7k
失敗から学ぶ個人開発
zaru_sakuraba
18
5.5k
伝わらない Issue の書き方
zaru_sakuraba
1
860
Ruby との対話 : pry を使い pry をデバッグし pry のバグを直す話
zaru_sakuraba
4
590
もう「クレデンシャルください」なんて言わせない
zaru_sakuraba
5
1.6k
個人プロジェクト現状報告会
zaru_sakuraba
0
130
僕と契約して、メソッドになってよ!
zaru_sakuraba
0
190
Other Decks in Technology
See All in Technology
AWS Devops Agent ~ 自動調査とSlack統合をやってみた! ~
kubomasataka
2
260
しろおびセキュリティへ ようこそ
log0417
0
190
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
13k
Agentic Coding 実践ワークショップ
watany
41
28k
AI時代のPMに求められるのは 「Ops」と「Enablement」
shimotaroo
1
460
「AIでできますか?」から「Agentを作ってみました」へ ~「理論上わかる」と「やってみる」の隔たりを埋める方法
applism118
11
7.4k
DatabricksホストモデルでAIコーディング環境を構築する
databricksjapan
0
200
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.3k
変化するコーディングエージェントとの現実的な付き合い方 〜Cursor安定択説と、ツールに依存しない「資産」〜
empitsu
3
190
20260129_CB_Kansai
takuyay0ne
0
190
GCASアップデート(202510-202601)
techniczna
0
200
The Engineer with a Three-Year Cycle - 2
e99h2121
0
200
Featured
See All Featured
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
200
Build your cross-platform service in a week with App Engine
jlugia
234
18k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Unsuck your backbone
ammeep
671
58k
What does AI have to do with Human Rights?
axbom
PRO
0
1.9k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
340
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.4k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
48
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
130
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.8k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Designing Powerful Visuals for Engaging Learning
tmiket
0
210
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
どんどん良くしていくぞ! という気持ち