From 9520cda07229bd59cb4fa2823d16cb43b384e3cd Mon Sep 17 00:00:00 2001 From: bug-author Date: Tue, 18 Nov 2025 01:46:39 +0500 Subject: [PATCH 1/2] perf: add bulk insert support for tags --- internal/contact/repository.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/internal/contact/repository.go b/internal/contact/repository.go index cc0b3d8..c009006 100644 --- a/internal/contact/repository.go +++ b/internal/contact/repository.go @@ -133,12 +133,26 @@ func (r *Repository) GetByEmail(email string) (*Contact, error) { } func insertTagIfNotExist(txn *sql.Tx, tags []Tag) error { - // todo: implement bulk inserts here - for _, tag := range tags { - _, err := txn.Exec(`INSERT OR IGNORE INTO tags (text) VALUES (?)`, tag.Text) - if err != nil { - return fmt.Errorf("failed to insert tag: %w", err) - } + if len(tags) == 0 { + return nil + } + + placeholders := make([]string, len(tags)) + args := make([]interface{}, len(tags)) + + for i, tag := range tags { + placeholders[i] = "?" + args[i] = tag.Text + } + + query := fmt.Sprintf( + `INSERT OR IGNORE INTO tags (text) VALUES %s`, + strings.Join(placeholders, ", "), + ) + + _, err := txn.Exec(query, args...) + if err != nil { + return fmt.Errorf("failed to bulk insert tags: %w", err) } return nil From 584830f1c9e6c5ca0eb66a7e347ea374dca60b66 Mon Sep 17 00:00:00 2001 From: bug-author Date: Tue, 18 Nov 2025 01:49:56 +0500 Subject: [PATCH 2/2] fix: correct placeholder syntax --- internal/contact/repository.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/contact/repository.go b/internal/contact/repository.go index c009006..2fa23d3 100644 --- a/internal/contact/repository.go +++ b/internal/contact/repository.go @@ -141,7 +141,7 @@ func insertTagIfNotExist(txn *sql.Tx, tags []Tag) error { args := make([]interface{}, len(tags)) for i, tag := range tags { - placeholders[i] = "?" + placeholders[i] = "(?)" args[i] = tag.Text }