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
Iteratorでページネーションを実現する
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
sonatard
September 24, 2024
Programming
1.5k
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Iteratorでページネーションを実現する
sonatard
September 24, 2024
More Decks by sonatard
See All by sonatard
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
640
Goのエラースタックトレースの歴史と今後
sonatard
19
17k
Go 1.22のEnhanced ServeMux chiから移行できるのか?
sonatard
5
740
GraphQL実践ノウハウv2
sonatard
17
3.2k
プロトコル、インターフェースとしてのGraphQL
sonatard
4
2.4k
GraphQL実践ノウハウ/graphql-knowhow
sonatard
42
12k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Go1.18から導入されるnetip package/netip-package
sonatard
3
1.3k
Jetpack ComposeとGraphQLによるServer Driven UI/jetpackcompose-grahpql-serverdrivernui
sonatard
1
2k
Other Decks in Programming
See All in Programming
エージェントを使い続けるためのメタワーク / Meta-work for keeping using the agent
rkaga
6
1.9k
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
180
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
240
見えないものを探る要求要件定義に必要な基本的思考 / invisible-requirement-thinking
minodriven
15
8.8k
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
4
1.3k
残高管理から台帳サービスへの進化
artoy
1
210
phperだってパンチカードでコーディングしたい
o0h
PRO
0
450
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
4.7k
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
140
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
5
5.8k
GraphQL の onError と Nullability のこれから
quramy
0
180
パスワード再設定メールのURLについて知っておこう
uyuki234
0
180
Featured
See All Featured
Odyssey Design
rkendrick25
PRO
2
890
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
440
Facilitating Awesome Meetings
lara
57
7.2k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Google's AI Overviews - The New Search
badams
0
1.6k
Skip the Path - Find Your Career Trail
mkilby
1
260
Side Projects
sachag
456
43k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Transcript
 1 *UFSBUPSͰϖʔδωʔγϣϯΛ࣮ݱ͢Δ (PͷΠςϨʔλਂງΓ/JHIU !TPOBUBSEͦͳଠגࣜձࣾ4UBDL
2 *UFSBUPSͷ͍ॴ w NBQ fi MUFSʜTMJDFपΓͰ͑ͦ͏ w ˠͳΜͱͳ͘Θ͔Δ w
ଞʹʁ
3 %#ͷϖʔδωʔγϣϯΛߟ͑ͯΈΔ w TQBOOFSDQBDLBHFͰ$MPVE4QBOOFSͷૢ࡞Λϥοϓ͍ͯ͠Δ w ҎԼ*UFSBUPSΛ͏લͷίʔυ cursorInfo = offset.NewCursorInfo() for
{ stmt := statement.ByCursor[domain.User](cursorInfo) users, pageInfo, err := spannerc.GetMulti(ctx, stmt) if err != nil { return nil, nil, fmt.Errorf(": %w", err) } // usersʹԿ͔͠Βͷॲཧ if !pageInfo.HasNextPage { break } cursorInfo.Cursor = pageInfo.EndCursor }
4 cursorInfo := offset.NewCursorInfo() for { stmt := statement.ByCursor[domain.User](cursorInfo) users,
pageInfo, err := spannerc.GetMulti(ctx, stmt) if err != nil { return nil, nil, fmt.Errorf(": %w", err) } // usersʹԿ͔͠Βͷॲཧ if !pageInfo.HasNextPage { break } cursorInfo.Cursor = pageInfo.EndCursor } ࣍ͷϖʔδ͕ͳ͚ΕGPS͔Βൈ͚Δ ࣍ͷϖʔδͷ$VSTPSΛߋ৽͢Δ
5 cursorInfo := offset.NewCursorInfo() for { stmt := statement.ByCursor[domain.User](cursorInfo) users,
pageInfo, err := spannerc.GetMulti(ctx, stmt) if err != nil { return nil, nil, fmt.Errorf(": %w", err) } // usersʹԿ͔͠Βͷॲཧ if !pageInfo.HasNextPage { break } cursorInfo.Cursor = pageInfo.EndCursor } CSFBLΛΕͨΓɺ݅Λؒҧ͑Δ
6 cursorInfo := offset.NewCursorInfo() for { stmt := statement.ByCursor[domain.User](cursorInfo) users,
pageInfo, err := spannerc.GetMulti(ctx, stmt) if err != nil { return nil, nil, fmt.Errorf(": %w", err) } // usersʹԿ͔͠Βͷॲཧ if !pageInfo.HasNextPage { break } // cursorInfo.Cursor = pageInfo.EndCursor } $VSTPSͷߋ৽ΛΕΔ
7 cursorInfo := offset.NewCursorInfo() for { stmt := statement.ByCursor[domain.User](cursorInfo) users,
pageInfo, err := spannerc.GetMulti(ctx, stmt) if err != nil { return nil, nil, fmt.Errorf(": %w", err) } // usersʹԿ͔͠Βͷॲཧ if users.Invalid() { continue } if !pageInfo.HasNextPage { break } cursorInfo.Cursor = pageInfo.EndCursor } $VSTPSͷߋ৽ΛΕͯDPOUJOVF
8 cursorInfo := offset.NewCursorInfo() for { stmt := statement.ByCursor[domain.User](cursorInfo) users,
pageInfo, err := spannerc.GetMulti(ctx, stmt) if err != nil { return nil, nil, fmt.Errorf(": %w", err) } // usersʹԿ͔͠Βͷॲཧ if users.Invalid() { continue } if !pageInfo.HasNextPage { break } cursorInfo.Cursor = pageInfo.EndCursor } ࠓ·ͰՄೳͳൣғͰ-JOUͰରԠ͍ͯͨ͠
9 stmt := statement.ByCursor[domain.User](offset.NewCursorInfo()) for users, err := range spannerc.GetMultiIter(ctx,
stmt) { if err != nil { return nil, nil, fmt.Errorf(": %w", err) } // usersʹԿ͔͠Βͷॲཧ if users.Invalid() { continue } } ϧʔϓͷϖʔδωʔγϣϯॲཧऴྃ݅ (FU.VMUJ*UFSʹӅṭ͞Ε͍ͯΔ 6TFSʹؔ࿈͢ΔॲཧͷΈΛॻ͚Α͘ͳͬͨ QBHF*OGPมͷΞΫηε͕ෆཁʹͳͬͨ
10 func GetMultiIter[T any](ctx context.Context, stmt offset.StatementWithCursor[T]) iter.Seq2[[]*T, error] {
return func(yield func([]*T, error) bool) { for { stmt.Statement.Params["offset"] = stmt.CursorInfo.Offset() ts, pageInfo, err := GetMulti[T](ctx, stmt) if !yield(ts, err) { return } if err != nil { return } if !pageInfo.HasNextPage { break } stmt.CursorInfo.Cursor = pageInfo.EndCursor } } } (FU.VMUJ*UFSͷ࣮
11 for users, err := range statement.ByCursor[domain.User](offset.NewCursorInfo()).All(ctx) { if err
!= nil { return nil, nil, fmt.Errorf(": %w", err) } // usersʹԿ͔͠Βͷॲཧ if users.Invalid() { continue } } ͓·͚ ͜Μͳ࣮ʹͨ͠ΒΑΓ(Pͷ*UFSBUPSΒ͍͠
12 *UFSBUPSͷ͍ॴ w ·ͱΊ w ϧʔϓΛநԽ͢Δ༻్Ͱ͑Δ w 'PSͷதͰ͋Δ݅ͰCSFBLDPOUJOVFΛ͍ͯ͠ΔͷͰ͋ΕγϯϓϧʹͰ͖Δ w Ͳ͜·Ͱ*UFSBUPSʹ͍ͯ͘͠ʁ
w *UFSBUPSײతʹಡΈͮΒ͍ͷͰɺͪΐͬͱͨ͜͠ͱͰ*UFSBUPSΛ͍͗͢Δͱٯʹ ίʔυ͕ಡΈͮΒ͘ͳΔ͔ w ϧʔϓʹ໌֬ͳ՝͕͋ΔɺͳॲཧΛ͍࣮ͭ͠ͳ͚ΕͳΒͳ͍߹ͳͲɺ ༻๏༻ྔΛकͬͯਖ਼͓͍͍ͩ͘͘͠͞ɻ
13 *UFSBUPSͷ͍ॴ w ͓·͚ w %BUBCBTFपลͰEBUBCBTFTRMQBDLBHFͳͲͰJP&0'ͳͲͷϋϯυϦϯά*UFSBUPS ͰෆཁʹͰ͖Δ w JP3FBEFSͳͲಉ༷ʁ w
͔͠͠JPQBDLBHFͷΠϯλʔϑΣʔε͕มΘΔͷ؆୯Ͱͳͦ͞͏ w ࠓޙඪ४ϥΠϒϥϦ͕ͲͷΑ͏ʹ*UFSBUPSʹରԠ͍͔ͯ͘͠ཁ