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
7日分も開けないレポートが180日分返るまで - 計測と修正のサイクルで回すActiveRec...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
hirocy
October 29, 2026
Programming
4
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
7日分も開けないレポートが180日分返るまで - 計測と修正のサイクルで回すActiveRecordパフォーマンス改善
hirocy
October 29, 2026
More Decks by hirocy
See All by hirocy
connect-goとsqlboilerで構築するクリーンアーキテクチャ
hirocy
0
2k
Other Decks in Programming
See All in Programming
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
350
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.4k
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
270
ChromeでローカルLLM
ryu1013
0
160
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
200
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
140
Apple Intelligenceとオンデバイス時代の到来
yahir0
0
150
APNsからLive Activityを開始する話
yumnumm
0
180
Vue.jsで作る空間解析アプリとCapacitorプラグインのData Bridge
hal_spidernight
1
110
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
430
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
330
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
7k
Featured
See All Featured
KATA
mclloyd
PRO
35
16k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Building Applications with DynamoDB
mza
96
7.3k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
580
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
420
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
290
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
530
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.5k
Accessibility Awareness
sabderemane
1
260
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Transcript
7日分も開けないレポートが 180日分返るまで 計測と修正のサイクルで回す ActiveRecord パフォーマンス改善 pixiv Inc. hirocy 2026.10.19
自己紹介 💼 23新卒/広告開発 ❤ Game/VTuber hirocy 広告なんでも Unit エンジニア https://x.com/hir0cy
pixiv Ads とは... 「pixiv」の運用型広告配信プラットフォーム https://ads.pixiv.net/lp 3
レポートは 3つのテーブルを集計する 広告主はレポートを見て、予算や配信を調整する 4 campaign_delivery_report_dailies # 日別の実績(過去日) delivery_report_hourlies # 時間別の実績(当日)
campaign_bills -> bills -> bill_months # 請求(消化金額)
7日分すら、レポートが開けない 「広告のレポートが 一切見られないのですが …」 5
計測と修正の サイクル を回す 6 スパンを見る 1 2 AI で逆引き もう一度計測
4 3 コードを直す
1リクエストで SQL が322クエリ発行されて いた 388 ms の SQL が1クエリ 7
短い SQL が244クエリ
Q1. どこが悪い? SELECT delivery_report_hourlies.* ... WHERE campaign_id IN (?) --
388 ms AI で発行元を探す campaigns_scope.includes(:delivery_report_hourlies, ...) 8
A1. 全期間を preload していた SELECT delivery_report_hourlies.* ... WHERE campaign_id IN
(?) -- report_at の条件が無い campaigns_scope.includes(:delivery_report_hourlies, ...) # includes は関連を丸ごと読む。N+1 対策で付けていた 1広告あたり 2,066行。使うのは当日の 15行だけ 9
修正1. 当日分だけ includes する # 当日分だけを読む関連 has_many :todays_delivery_report_hourlies, -> {
where(report_at: Time.current.all_day) } # 期間に今日を含むときだけ includes(:todays_delivery_report_hourlies) 時間別が必要なのは当日分だけ 10
Q2. どこが悪い? SELECT bills.* FROM bills WHERE bills.id = ?
LIMIT ? -- ×122 AI で発行元を探す fixed_bills = campaign_bills.joins(bill: :bill_month) fixed_bills.map { |cb| cb.bill.bill_month.month } 11
A2. joins は関連をロードしない fixed_bills = campaign_bills.joins(bill: :bill_month) # joins は
JOIN するだけ。bill はロードされない fixed_bills.map { |cb| cb.bill.bill_month.month } # 辿るたびに1件ずつ SELECT(bills、bill_months 各122回) joins を書いていても、 N+1 になる 12
修正2. 必要な2列だけ pluck する campaign_bills .joins(bill: :bill_month) .pluck('campaign_bills.price', 'bill_months.month') 1つの
SQL で、返したい値だけを取る 13
180日分まで返せるようになった 322 → 59 クエリ SQL のクエリ数 取得期間の上限 90日 →
180日 14
重いページもトレースをもとに直せる スパンを見る AI で逆引き コードを直す • includes は、範囲を絞らないと全件を読む • joins
は、関連をロードしない 15 もう一度計測