mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 07:28:27 +00:00
Fix duplicate writers (#1376)
* Fix writers * Don't use writers in both shared and sqlite3
This commit is contained in:
parent
89c772fb78
commit
a9f4d83d30
4 changed files with 19 additions and 25 deletions
|
@ -83,7 +83,6 @@ const selectKnownUsersSQL = "" +
|
||||||
|
|
||||||
type currentRoomStateStatements struct {
|
type currentRoomStateStatements struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
writer sqlutil.Writer
|
|
||||||
upsertRoomStateStmt *sql.Stmt
|
upsertRoomStateStmt *sql.Stmt
|
||||||
deleteRoomStateByEventIDStmt *sql.Stmt
|
deleteRoomStateByEventIDStmt *sql.Stmt
|
||||||
selectRoomIDsWithMembershipStmt *sql.Stmt
|
selectRoomIDsWithMembershipStmt *sql.Stmt
|
||||||
|
@ -95,8 +94,7 @@ type currentRoomStateStatements struct {
|
||||||
|
|
||||||
func NewSqliteCurrentRoomStateTable(db *sql.DB) (tables.CurrentRoomState, error) {
|
func NewSqliteCurrentRoomStateTable(db *sql.DB) (tables.CurrentRoomState, error) {
|
||||||
s := ¤tRoomStateStatements{
|
s := ¤tRoomStateStatements{
|
||||||
db: db,
|
db: db,
|
||||||
writer: sqlutil.NewExclusiveWriter(),
|
|
||||||
}
|
}
|
||||||
_, err := db.Exec(currentRoomStateSchema)
|
_, err := db.Exec(currentRoomStateSchema)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -177,11 +175,9 @@ func (s *currentRoomStateStatements) SelectRoomIDsWithMembership(
|
||||||
func (s *currentRoomStateStatements) DeleteRoomStateByEventID(
|
func (s *currentRoomStateStatements) DeleteRoomStateByEventID(
|
||||||
ctx context.Context, txn *sql.Tx, eventID string,
|
ctx context.Context, txn *sql.Tx, eventID string,
|
||||||
) error {
|
) error {
|
||||||
return s.writer.Do(s.db, txn, func(txn *sql.Tx) error {
|
stmt := sqlutil.TxStmt(txn, s.deleteRoomStateByEventIDStmt)
|
||||||
stmt := sqlutil.TxStmt(txn, s.deleteRoomStateByEventIDStmt)
|
_, err := stmt.ExecContext(ctx, eventID)
|
||||||
_, err := stmt.ExecContext(ctx, eventID)
|
return err
|
||||||
return err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *currentRoomStateStatements) UpsertRoomState(
|
func (s *currentRoomStateStatements) UpsertRoomState(
|
||||||
|
@ -194,20 +190,18 @@ func (s *currentRoomStateStatements) UpsertRoomState(
|
||||||
}
|
}
|
||||||
|
|
||||||
// upsert state event
|
// upsert state event
|
||||||
return s.writer.Do(s.db, txn, func(txn *sql.Tx) error {
|
stmt := sqlutil.TxStmt(txn, s.upsertRoomStateStmt)
|
||||||
stmt := sqlutil.TxStmt(txn, s.upsertRoomStateStmt)
|
_, err = stmt.ExecContext(
|
||||||
_, err = stmt.ExecContext(
|
ctx,
|
||||||
ctx,
|
event.RoomID(),
|
||||||
event.RoomID(),
|
event.EventID(),
|
||||||
event.EventID(),
|
event.Type(),
|
||||||
event.Type(),
|
event.Sender(),
|
||||||
event.Sender(),
|
*event.StateKey(),
|
||||||
*event.StateKey(),
|
headeredJSON,
|
||||||
headeredJSON,
|
contentVal,
|
||||||
contentVal,
|
)
|
||||||
)
|
return err
|
||||||
return err
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *currentRoomStateStatements) SelectEventsWithEventIDs(
|
func (s *currentRoomStateStatements) SelectEventsWithEventIDs(
|
||||||
|
|
|
@ -122,7 +122,7 @@ func Open(dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches)
|
||||||
d.Database = shared.Database{
|
d.Database = shared.Database{
|
||||||
DB: d.db,
|
DB: d.db,
|
||||||
Cache: cache,
|
Cache: cache,
|
||||||
Writer: sqlutil.NewExclusiveWriter(),
|
Writer: d.writer,
|
||||||
EventsTable: d.events,
|
EventsTable: d.events,
|
||||||
EventTypesTable: d.eventTypes,
|
EventTypesTable: d.eventTypes,
|
||||||
EventStateKeysTable: d.eventStateKeys,
|
EventStateKeysTable: d.eventStateKeys,
|
||||||
|
|
|
@ -80,7 +80,7 @@ func NewDatabase(dbProperties *config.DatabaseOptions) (*SyncServerDatasource, e
|
||||||
}
|
}
|
||||||
d.Database = shared.Database{
|
d.Database = shared.Database{
|
||||||
DB: d.db,
|
DB: d.db,
|
||||||
Writer: sqlutil.NewDummyWriter(),
|
Writer: d.writer,
|
||||||
Invites: invites,
|
Invites: invites,
|
||||||
AccountData: accountData,
|
AccountData: accountData,
|
||||||
OutputEvents: events,
|
OutputEvents: events,
|
||||||
|
|
|
@ -93,7 +93,7 @@ func (d *SyncServerDatasource) prepare() (err error) {
|
||||||
}
|
}
|
||||||
d.Database = shared.Database{
|
d.Database = shared.Database{
|
||||||
DB: d.db,
|
DB: d.db,
|
||||||
Writer: sqlutil.NewExclusiveWriter(),
|
Writer: d.writer,
|
||||||
Invites: invites,
|
Invites: invites,
|
||||||
AccountData: accountData,
|
AccountData: accountData,
|
||||||
OutputEvents: events,
|
OutputEvents: events,
|
||||||
|
|
Loading…
Reference in a new issue