File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import { existsSync } from "node:fs";
2929import { getDrizzle } from "@/lib/drizzle" ;
3030import { section as sectionTable } from "@/schema/chat" ;
3131import "dotenv/config" ;
32+ import { sql } from "drizzle-orm" ;
3233
3334let doWrite = false ;
3435let doCheckDiff = false ;
@@ -114,16 +115,20 @@ for (const id in revisions) {
114115
115116if ( doWrite ) {
116117 const drizzle = await getDrizzle ( ) ;
117- for ( const id in revisions ) {
118+ const batchSize = 100 ;
119+ const entries = Object . entries ( revisions ) ;
120+ for ( let i = 0 ; i < entries . length ; i += batchSize ) {
118121 await drizzle
119122 . insert ( sectionTable )
120- . values ( {
121- sectionId : id ,
122- pagePath : revisions [ id ] . page ,
123- } )
123+ . values (
124+ entries . slice ( i , i + batchSize ) . map ( ( [ id , data ] ) => ( {
125+ sectionId : id ,
126+ pagePath : data . page ,
127+ } ) )
128+ )
124129 . onConflictDoUpdate ( {
125130 target : sectionTable . sectionId ,
126- set : { pagePath : revisions [ id ] . page } ,
131+ set : { pagePath : sql `excluded."pagePath"` } ,
127132 } ) ;
128133 }
129134
You can’t perform that action at this time.
0 commit comments