From 328f2892e01056b809851e5338ef184df5033906 Mon Sep 17 00:00:00 2001 From: David Schlachter Date: Wed, 7 Jan 2026 22:53:13 -0500 Subject: Much faster initial setup --- setup.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'setup.go') diff --git a/setup.go b/setup.go index 47005e1..49aedd4 100644 --- a/setup.go +++ b/setup.go @@ -3,12 +3,13 @@ package main import ( "bufio" "database/sql" - "encoding/json" "fmt" "html/template" "log" "os" "strings" + + "github.com/goccy/go-json" ) type rawDictionaryEntry struct { @@ -65,10 +66,15 @@ func readDictionary(db *sql.DB) error { panic(err) } + tx, err := db.Begin() + if err != nil { + return fmt.Errorf("starting transaction: %w", err) + } + // Set up a prepared statement - stmt, err := db.Prepare("insert into words(word, definition) values(?, ?)") + stmt, err := tx.Prepare("insert into words(word, definition) values(?, ?)") if err != nil { - log.Fatal(err) + return fmt.Errorf("preparing statement: %w", err) } defer stmt.Close() @@ -141,6 +147,10 @@ func readDictionary(db *sql.DB) error { return fmt.Errorf("scanning: %w", err) } + if err := tx.Commit(); err != nil { + return fmt.Errorf("committing: %w", err) + } + log.Printf("prepared %d dictionary entries", wordsAdded) return nil -- cgit v1.2.3