diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-07-21 15:48:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-21 15:48:21 +0100 |
commit | b6bc132485ec4d6b37815929f6a4e73e5a062d3b (patch) | |
tree | dddea5f8e9fdbd25905822971a908218eb6697a6 /syncapi/storage/sqlite3/account_data_table.go | |
parent | 1d72ce8b7ab759555503df37af666529749b489c (diff) |
Use TransactionWriter in other component SQLite (#1209)
* Use TransactionWriter on other component SQLites
* Fix sync API tests
* Fix panic in media API
* Fix a couple of transactions
* Fix wrong query, add some logging output
* Add debug logging into StoreEvent
* Adjust InsertRoomNID
* Update logging
Diffstat (limited to 'syncapi/storage/sqlite3/account_data_table.go')
-rw-r--r-- | syncapi/storage/sqlite3/account_data_table.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/syncapi/storage/sqlite3/account_data_table.go b/syncapi/storage/sqlite3/account_data_table.go index ae5caa4e..609cef14 100644 --- a/syncapi/storage/sqlite3/account_data_table.go +++ b/syncapi/storage/sqlite3/account_data_table.go @@ -20,6 +20,7 @@ import ( "database/sql" "github.com/matrix-org/dendrite/internal" + "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/syncapi/storage/tables" "github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/gomatrixserverlib" @@ -49,6 +50,8 @@ const selectMaxAccountDataIDSQL = "" + "SELECT MAX(id) FROM syncapi_account_data_type" type accountDataStatements struct { + db *sql.DB + writer *sqlutil.TransactionWriter streamIDStatements *streamIDStatements insertAccountDataStmt *sql.Stmt selectMaxAccountDataIDStmt *sql.Stmt @@ -57,6 +60,8 @@ type accountDataStatements struct { func NewSqliteAccountDataTable(db *sql.DB, streamID *streamIDStatements) (tables.AccountData, error) { s := &accountDataStatements{ + db: db, + writer: sqlutil.NewTransactionWriter(), streamIDStatements: streamID, } _, err := db.Exec(accountDataSchema) @@ -79,12 +84,15 @@ func (s *accountDataStatements) InsertAccountData( ctx context.Context, txn *sql.Tx, userID, roomID, dataType string, ) (pos types.StreamPosition, err error) { - pos, err = s.streamIDStatements.nextStreamID(ctx, txn) - if err != nil { - return - } - _, err = txn.Stmt(s.insertAccountDataStmt).ExecContext(ctx, pos, userID, roomID, dataType) - return + return pos, s.writer.Do(s.db, nil, func(txn *sql.Tx) error { + var err error + pos, err = s.streamIDStatements.nextStreamID(ctx, txn) + if err != nil { + return err + } + _, err = txn.Stmt(s.insertAccountDataStmt).ExecContext(ctx, pos, userID, roomID, dataType) + return err + }) } func (s *accountDataStatements) SelectAccountDataInRange( |