mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-01 05:42:46 +00:00
Add some error wrapping to sync API, use background context for sync (#1363)
* Add some error wrapping to sync API * Don't use request context for BeginTx until mattn/go-sqlite3#764 is fixed
This commit is contained in:
parent
fee1c22790
commit
c42c70597c
2 changed files with 26 additions and 19 deletions
|
@ -451,7 +451,7 @@ func (d *Database) addPDUDeltaToResponse(
|
|||
wantFullState bool,
|
||||
res *types.Response,
|
||||
) (joinedRoomIDs []string, err error) {
|
||||
txn, err := d.DB.BeginTx(ctx, &txReadOnlySnapshot)
|
||||
txn, err := d.DB.BeginTx(context.TODO(), &txReadOnlySnapshot) // TODO: check mattn/go-sqlite3#764
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -577,20 +577,23 @@ func (d *Database) IncrementalSync(
|
|||
joinedRoomIDs, err = d.addPDUDeltaToResponse(
|
||||
ctx, device, r, numRecentEventsPerRoom, wantFullState, res,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("d.addPDUDeltaToResponse: %w", err)
|
||||
}
|
||||
} else {
|
||||
joinedRoomIDs, err = d.CurrentRoomState.SelectRoomIDsWithMembership(
|
||||
ctx, nil, device.UserID, gomatrixserverlib.Join,
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("d.CurrentRoomState.SelectRoomIDsWithMembership: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
err = d.addEDUDeltaToResponse(
|
||||
fromPos, toPos, joinedRoomIDs, res,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("d.addEDUDeltaToResponse: %w", err)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
@ -632,7 +635,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(ctx, &txReadOnlySnapshot)
|
||||
txn, err := d.DB.BeginTx(context.TODO(), &txReadOnlySnapshot) // TODO: check mattn/go-sqlite3#764
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -719,7 +722,7 @@ func (d *Database) CompleteSync(
|
|||
ctx, res, device.UserID, numRecentEventsPerRoom,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("d.getResponseWithPDUsForCompleteSync: %w", err)
|
||||
}
|
||||
|
||||
// Use a zero value SyncPosition for fromPos so all EDU states are added.
|
||||
|
@ -727,7 +730,7 @@ func (d *Database) CompleteSync(
|
|||
types.NewStreamToken(0, 0, nil), toPos, joinedRoomIDs, res,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("d.addEDUDeltaToResponse: %w", err)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
@ -753,7 +756,7 @@ func (d *Database) addInvitesToResponse(
|
|||
ctx, txn, userID, r,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("d.Invites.SelectInviteEventsInRange: %w", err)
|
||||
}
|
||||
for roomID, inviteEvent := range invites {
|
||||
ir := types.NewInviteResponse(inviteEvent)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue