@@ -111,19 +111,24 @@ func (db *BindingStore) PutBindings(ctx context.Context, longTerm view.Identity,
111111 }
112112
113113 // Build single INSERT with multiple VALUES
114- query := fmt .Sprintf (`INSERT INTO %s (ephemeral_hash, long_term_id) VALUES ` , db .table )
114+ // prepare query placeholder and arguments
115+ placeholders := make ([]string , len (ephemerals )+ 1 )
116+ args := make ([]any , 0 , (len (ephemerals )+ 1 )* 2 )
115117
116- var args = []interface {}{}
117- argsReferences := []string {"($1, $2)" }
118+ // first item it the longTerm itself
119+ i := 0
120+ placeholders [i ] = fmt .Sprintf ("($%d,$%d)" , i * 2 + 1 , i * 2 + 2 )
118121 args = append (args , longTerm .UniqueID (), longTerm )
119- for i , eph := range ephemerals {
122+
123+ // next we go through our ephemerals
124+ for _ , eph := range ephemerals {
125+ i ++
126+ placeholders [i ] = fmt .Sprintf ("($%d,$%d)" , i * 2 + 1 , i * 2 + 2 )
120127 args = append (args , eph .UniqueID (), longTerm )
121- oneArgRef := fmt .Sprintf ("($%d, $%d)" , i * 2 + 3 , i * 2 + 4 )
122- argsReferences = append (argsReferences , oneArgRef )
123128 }
124129
125- query += strings . Join ( argsReferences , ", " )
126- query += " ON CONFLICT DO NOTHING;"
130+ query := fmt . Sprintf ( `INSERT INTO %s (ephemeral_hash, long_term_id) VALUES %s ON CONFLICT DO NOTHING;` ,
131+ db . table , strings . Join ( placeholders , "," ))
127132
128133 logger .DebugfContext (ctx , "executing bulk insert: %s" , query )
129134
0 commit comments