diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2021-06-07 10:51:19 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-07 08:51:19 +0100 |
commit | f18001ecbbfe2c70c5bce41e0f8373750f528ace (patch) | |
tree | 56517d84c5850d747eeca5bc93f3cba1aa65fd33 /appservice | |
parent | b0aa101dcd568dbb8e6a5db42e358442a6ff1182 (diff) |
Split the select+update query for txn_id counter (#1855)
The update part wasn't executed actually for SQLite, so it is moved to
a separate statement.
Fixes #1852.
Signed-off-by: Bohdan Horbeshko <bodqhrohro@gmail.com>
Diffstat (limited to 'appservice')
-rw-r--r-- | appservice/storage/sqlite3/txn_id_counter_table.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/appservice/storage/sqlite3/txn_id_counter_table.go b/appservice/storage/sqlite3/txn_id_counter_table.go index b2940e35..f2e902f9 100644 --- a/appservice/storage/sqlite3/txn_id_counter_table.go +++ b/appservice/storage/sqlite3/txn_id_counter_table.go @@ -32,14 +32,18 @@ INSERT OR IGNORE INTO appservice_counters (name, last_id) VALUES('txn_id', 1); ` const selectTxnIDSQL = ` - SELECT last_id FROM appservice_counters WHERE name='txn_id'; - UPDATE appservice_counters SET last_id=last_id+1 WHERE name='txn_id'; + SELECT last_id FROM appservice_counters WHERE name='txn_id' +` + +const updateTxnIDSQL = ` + UPDATE appservice_counters SET last_id=last_id+1 WHERE name='txn_id' ` type txnStatements struct { db *sql.DB writer sqlutil.Writer selectTxnIDStmt *sql.Stmt + updateTxnIDStmt *sql.Stmt } func (s *txnStatements) prepare(db *sql.DB, writer sqlutil.Writer) (err error) { @@ -54,6 +58,10 @@ func (s *txnStatements) prepare(db *sql.DB, writer sqlutil.Writer) (err error) { return } + if s.updateTxnIDStmt, err = db.Prepare(updateTxnIDSQL); err != nil { + return + } + return } @@ -63,6 +71,11 @@ func (s *txnStatements) selectTxnID( ) (txnID int, err error) { err = s.writer.Do(s.db, nil, func(txn *sql.Tx) error { err := s.selectTxnIDStmt.QueryRowContext(ctx).Scan(&txnID) + if err != nil { + return err + } + + _, err = s.updateTxnIDStmt.ExecContext(ctx) return err }) return |