Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit511a4a2

Browse files
refactor: stream batched items to db during backfill (#229)
Streams and upserts in chunks as items arrive, instead of collecting all first.- Chunks of 250 items- Upsert runs while fetch continues- Logging: removes mid-sync count log (total unknown until done)
1 parent8fe9847 commit511a4a2

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

‎packages/sync-engine/src/stripeSync.ts‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,25 +1009,27 @@ export class StripeSync {
10091009
fetch:()=>Stripe.ApiListPromise<T>,
10101010
upsert:(items:T[])=>Promise<T[]>
10111011
):Promise<Sync>{
1012-
constitems:T[]=[]
1012+
constchunkSize=250
1013+
letchunk:T[]=[]
1014+
letsynced=0
10131015

10141016
this.config.logger?.info('Fetching items to sync from Stripe')
10151017
forawait(constitemoffetch()){
1016-
items.push(item)
1017-
}
1018+
chunk.push(item)
1019+
synced++
1020+
if(synced%1000===0)this.config.logger?.info(`Synced${synced} items`)
10181021

1019-
if(!items.length)return{synced:0}
1022+
if(chunk.length>=chunkSize){
1023+
awaitupsert(chunk)
1024+
chunk=[]
1025+
}
1026+
}
10201027

1021-
this.config.logger?.info(`Upserting${items.length} items`)
1022-
constchunkSize=250
1023-
for(leti=0;i<items.length;i+=chunkSize){
1024-
constchunk=items.slice(i,i+chunkSize)
1028+
if(chunk.length>0)awaitupsert(chunk)
10251029

1026-
awaitupsert(chunk)
1027-
}
1028-
this.config.logger?.info('Upserted items')
1030+
this.config.logger?.info(`Upserted${synced} items`)
10291031

1030-
return{synced:items.length}
1032+
return{ synced}
10311033
}
10321034

10331035
privateasyncupsertCharges(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp