mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 14:12:47 +00:00
Assign room NIDs, event type NIDs and state key NIDs outside of database transactions (#2265)
* Assign room NIDs and state key NIDs outside of database transactions * In roomserver storage package too * Don't take a `txn` parameter, clean up SQLite
This commit is contained in:
parent
4e64c270db
commit
191486438c
5 changed files with 42 additions and 62 deletions
|
@ -18,6 +18,7 @@ package sqlite3
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal"
|
||||
|
@ -39,7 +40,8 @@ const eventStateKeysSchema = `
|
|||
// Same as insertEventTypeNIDSQL
|
||||
const insertEventStateKeyNIDSQL = `
|
||||
INSERT INTO roomserver_event_state_keys (event_state_key) VALUES ($1)
|
||||
ON CONFLICT DO NOTHING;
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING event_state_key_nid;
|
||||
`
|
||||
|
||||
const selectEventStateKeyNIDSQL = `
|
||||
|
@ -89,17 +91,12 @@ func prepareEventStateKeysTable(db *sql.DB) (tables.EventStateKeys, error) {
|
|||
|
||||
func (s *eventStateKeyStatements) InsertEventStateKeyNID(
|
||||
ctx context.Context, txn *sql.Tx, eventStateKey string,
|
||||
) (types.EventStateKeyNID, error) {
|
||||
) (eventStateKeyNID types.EventStateKeyNID, err error) {
|
||||
insertStmt := sqlutil.TxStmt(txn, s.insertEventStateKeyNIDStmt)
|
||||
res, err := insertStmt.ExecContext(ctx, eventStateKey)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
if err := insertStmt.QueryRowContext(ctx, eventStateKey).Scan(&eventStateKeyNID); err != nil {
|
||||
return 0, fmt.Errorf("resultStmt.QueryRowContext.Scan: %w", err)
|
||||
}
|
||||
eventStateKeyNID, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return types.EventStateKeyNID(eventStateKeyNID), err
|
||||
return
|
||||
}
|
||||
|
||||
func (s *eventStateKeyStatements) SelectEventStateKeyNID(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue