mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 14:12:47 +00:00
Merge branch 'master' into matthew/peeking
This commit is contained in:
commit
28219c66f5
25 changed files with 530 additions and 276 deletions
|
@ -138,43 +138,14 @@ func (d *Database) GetStateEventsForRoom(
|
|||
return
|
||||
}
|
||||
|
||||
func (d *Database) SyncStreamPosition(ctx context.Context) (types.StreamPosition, error) {
|
||||
var maxID int64
|
||||
var err error
|
||||
err = sqlutil.WithTransaction(d.DB, func(txn *sql.Tx) error {
|
||||
maxID, err = d.OutputEvents.SelectMaxEventID(ctx, txn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var maxAccountDataID int64
|
||||
maxAccountDataID, err = d.AccountData.SelectMaxAccountDataID(ctx, txn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if maxAccountDataID > maxID {
|
||||
maxID = maxAccountDataID
|
||||
}
|
||||
var maxInviteID int64
|
||||
maxInviteID, err = d.Invites.SelectMaxInviteID(ctx, txn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if maxInviteID > maxID {
|
||||
maxID = maxInviteID
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return types.StreamPosition(maxID), err
|
||||
}
|
||||
|
||||
// AddInviteEvent stores a new invite event for a user.
|
||||
// If the invite was successfully stored this returns the stream ID it was stored at.
|
||||
// Returns an error if there was a problem communicating with the database.
|
||||
func (d *Database) AddInviteEvent(
|
||||
ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent,
|
||||
) (sp types.StreamPosition, err error) {
|
||||
_ = d.Writer.Do(nil, nil, func(_ *sql.Tx) error {
|
||||
sp, err = d.Invites.InsertInviteEvent(ctx, nil, inviteEvent)
|
||||
_ = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||
sp, err = d.Invites.InsertInviteEvent(ctx, txn, inviteEvent)
|
||||
return nil
|
||||
})
|
||||
return
|
||||
|
@ -185,8 +156,8 @@ func (d *Database) AddInviteEvent(
|
|||
func (d *Database) RetireInviteEvent(
|
||||
ctx context.Context, inviteEventID string,
|
||||
) (sp types.StreamPosition, err error) {
|
||||
_ = d.Writer.Do(nil, nil, func(_ *sql.Tx) error {
|
||||
sp, err = d.Invites.DeleteInviteEvent(ctx, inviteEventID)
|
||||
_ = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||
sp, err = d.Invites.DeleteInviteEvent(ctx, txn, inviteEventID)
|
||||
return nil
|
||||
})
|
||||
return
|
||||
|
@ -469,7 +440,7 @@ func (d *Database) addPDUDeltaToResponse(
|
|||
wantFullState bool,
|
||||
res *types.Response,
|
||||
) (joinedRoomIDs []string, err error) {
|
||||
txn, err := d.DB.BeginTx(context.TODO(), &txReadOnlySnapshot) // TODO: check mattn/go-sqlite3#764
|
||||
txn, err := d.DB.BeginTx(ctx, &txReadOnlySnapshot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -655,7 +626,7 @@ func (d *Database) getResponseWithPDUsForCompleteSync(
|
|||
// a consistent view of the database throughout. This includes extracting the sync position.
|
||||
// This does have the unfortunate side-effect that all the matrixy logic resides in this function,
|
||||
// but it's better to not hide the fact that this is being done in a transaction.
|
||||
txn, err := d.DB.BeginTx(context.TODO(), &txReadOnlySnapshot) // TODO: check mattn/go-sqlite3#764
|
||||
txn, err := d.DB.BeginTx(ctx, &txReadOnlySnapshot)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -1224,15 +1195,6 @@ func (d *Database) SendToDeviceUpdatesWaiting(
|
|||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (d *Database) AddSendToDeviceEvent(
|
||||
ctx context.Context, txn *sql.Tx,
|
||||
userID, deviceID, content string,
|
||||
) error {
|
||||
return d.SendToDevice.InsertSendToDeviceMessage(
|
||||
ctx, txn, userID, deviceID, content,
|
||||
)
|
||||
}
|
||||
|
||||
func (d *Database) StoreNewSendForDeviceMessage(
|
||||
ctx context.Context, streamPos types.StreamPosition, userID, deviceID string, event gomatrixserverlib.SendToDeviceEvent,
|
||||
) (types.StreamPosition, error) {
|
||||
|
@ -1243,7 +1205,7 @@ func (d *Database) StoreNewSendForDeviceMessage(
|
|||
// Delegate the database write task to the SendToDeviceWriter. It'll guarantee
|
||||
// that we don't lock the table for writes in more than one place.
|
||||
err = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||
return d.AddSendToDeviceEvent(
|
||||
return d.SendToDevice.InsertSendToDeviceMessage(
|
||||
ctx, txn, userID, deviceID, string(j),
|
||||
)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue