Skip to content

Commit 1e95e6d

Browse files
authored
perf(sqldb): batch insert archived workflow labels. (#15821)
Signed-off-by: shuangkun <tsk2013uestc@163.com>
1 parent 23266a7 commit 1e95e6d

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

persist/sqldb/workflow_archive.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,19 @@ func (r *workflowArchive) ArchiveWorkflow(ctx context.Context, wf *wfv1.Workflow
154154
if err != nil {
155155
return err
156156
}
157-
// insert the labels
158-
for key, value := range wf.GetLabels() {
159-
_, err := sess.Collection(archiveLabelsTableName).
160-
Insert(&archivedWorkflowLabelRecord{
161-
ClusterName: r.clusterName,
162-
UID: string(wf.UID),
163-
Key: key,
164-
Value: value,
165-
})
166-
if err != nil {
157+
// insert all labels in a single multi-row INSERT
158+
labels := wf.GetLabels()
159+
if len(labels) > 0 {
160+
uid := string(wf.UID)
161+
batch := sess.SQL().
162+
InsertInto(archiveLabelsTableName).
163+
Columns("clustername", "uid", "name", "value").
164+
Batch(len(labels))
165+
for key, value := range labels {
166+
batch.Values(r.clusterName, uid, key, value)
167+
}
168+
batch.Done()
169+
if err := batch.Wait(); err != nil {
167170
return err
168171
}
169172
}

0 commit comments

Comments
 (0)