mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 05:43:09 -06:00
Fix createAccount and friends
This commit is contained in:
parent
88199c8ee0
commit
fe4723faa6
|
|
@ -41,6 +41,7 @@ type Database struct {
|
|||
|
||||
accountWriter *sqlutil.TransactionWriter
|
||||
profileWriter *sqlutil.TransactionWriter
|
||||
accountDataWriter *sqlutil.TransactionWriter
|
||||
threepidWriter *sqlutil.TransactionWriter
|
||||
}
|
||||
|
||||
|
|
@ -85,6 +86,7 @@ func NewDatabase(dataSourceName string, serverName gomatrixserverlib.ServerName)
|
|||
serverName: serverName,
|
||||
accountWriter: sqlutil.NewTransactionWriter(),
|
||||
profileWriter: sqlutil.NewTransactionWriter(),
|
||||
accountDataWriter: sqlutil.NewTransactionWriter(),
|
||||
threepidWriter: sqlutil.NewTransactionWriter(),
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -148,9 +150,9 @@ func (d *Database) CreateGuestAccount(ctx context.Context) (acc *api.Account, er
|
|||
}
|
||||
localpart := strconv.FormatInt(numLocalpart, 10)
|
||||
acc, err = d.createAccount(ctx, txn, localpart, "", "")
|
||||
return err
|
||||
return nil
|
||||
})
|
||||
return acc, err
|
||||
return
|
||||
}
|
||||
|
||||
// CreateAccount makes a new account with the given login name and password, and creates an empty profile
|
||||
|
|
@ -160,9 +162,9 @@ func (d *Database) CreateAccount(
|
|||
ctx context.Context, localpart, plaintextPassword, appserviceID string,
|
||||
) (acc *api.Account, err error) {
|
||||
// Create one account at a time else we can get 'database is locked'.
|
||||
err = d.accountWriter.Do(d.db, func(txn *sql.Tx) error {
|
||||
_ = d.accountWriter.Do(d.db, func(txn *sql.Tx) error {
|
||||
acc, err = d.createAccount(ctx, txn, localpart, plaintextPassword, appserviceID)
|
||||
return err
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
|
@ -179,14 +181,23 @@ func (d *Database) createAccount(
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := d.profiles.insertProfile(ctx, txn, localpart); err != nil {
|
||||
|
||||
err = d.profileWriter.Do(d.db, func(txn *sql.Tx) error {
|
||||
if err = d.profiles.insertProfile(ctx, txn, localpart); err != nil {
|
||||
if isConstraintError(err) {
|
||||
return nil, sqlutil.ErrUserExists
|
||||
return sqlutil.ErrUserExists
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
_ = txn.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := d.accountDatas.insertAccountData(ctx, txn, localpart, "", "m.push_rules", json.RawMessage(`{
|
||||
err = d.accountDataWriter.Do(d.db, func(txn *sql.Tx) error {
|
||||
return d.accountDatas.insertAccountData(ctx, txn, localpart, "", "m.push_rules", json.RawMessage(`{
|
||||
"global": {
|
||||
"content": [],
|
||||
"override": [],
|
||||
|
|
@ -194,9 +205,13 @@ func (d *Database) createAccount(
|
|||
"sender": [],
|
||||
"underride": []
|
||||
}
|
||||
}`)); err != nil {
|
||||
}`))
|
||||
})
|
||||
if err != nil {
|
||||
_ = txn.Rollback()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return d.accounts.insertAccount(ctx, txn, localpart, hash, appserviceID)
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +223,7 @@ func (d *Database) createAccount(
|
|||
func (d *Database) SaveAccountData(
|
||||
ctx context.Context, localpart, roomID, dataType string, content json.RawMessage,
|
||||
) error {
|
||||
return d.accountWriter.Do(d.db, func(txn *sql.Tx) error {
|
||||
return d.accountDataWriter.Do(d.db, func(txn *sql.Tx) error {
|
||||
return d.accountDatas.insertAccountData(ctx, txn, localpart, roomID, dataType, content)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue