mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 06:43:09 -06:00
Sync API tweaks
This commit is contained in:
parent
3f9b829bc5
commit
5da816d3a4
|
|
@ -110,9 +110,10 @@ func (s *inviteEventsStatements) InsertInviteEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *inviteEventsStatements) DeleteInviteEvent(
|
func (s *inviteEventsStatements) DeleteInviteEvent(
|
||||||
ctx context.Context, inviteEventID string,
|
ctx context.Context, txn *sql.Tx, inviteEventID string,
|
||||||
) (sp types.StreamPosition, err error) {
|
) (sp types.StreamPosition, err error) {
|
||||||
err = s.deleteInviteEventStmt.QueryRowContext(ctx, inviteEventID).Scan(&sp)
|
stmt := sqlutil.TxStmt(txn, s.deleteInviteEventStmt)
|
||||||
|
err = stmt.QueryRowContext(ctx, inviteEventID).Scan(&sp)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,8 +139,8 @@ func (d *Database) GetStateEventsForRoom(
|
||||||
func (d *Database) AddInviteEvent(
|
func (d *Database) AddInviteEvent(
|
||||||
ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent,
|
ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent,
|
||||||
) (sp types.StreamPosition, err error) {
|
) (sp types.StreamPosition, err error) {
|
||||||
_ = d.Writer.Do(nil, nil, func(_ *sql.Tx) error {
|
_ = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
sp, err = d.Invites.InsertInviteEvent(ctx, nil, inviteEvent)
|
sp, err = d.Invites.InsertInviteEvent(ctx, txn, inviteEvent)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|
@ -151,8 +151,8 @@ func (d *Database) AddInviteEvent(
|
||||||
func (d *Database) RetireInviteEvent(
|
func (d *Database) RetireInviteEvent(
|
||||||
ctx context.Context, inviteEventID string,
|
ctx context.Context, inviteEventID string,
|
||||||
) (sp types.StreamPosition, err error) {
|
) (sp types.StreamPosition, err error) {
|
||||||
_ = d.Writer.Do(nil, nil, func(_ *sql.Tx) error {
|
_ = d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||||
sp, err = d.Invites.DeleteInviteEvent(ctx, inviteEventID)
|
sp, err = d.Invites.DeleteInviteEvent(ctx, txn, inviteEventID)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|
@ -422,7 +422,7 @@ func (d *Database) addPDUDeltaToResponse(
|
||||||
wantFullState bool,
|
wantFullState bool,
|
||||||
res *types.Response,
|
res *types.Response,
|
||||||
) (joinedRoomIDs []string, err error) {
|
) (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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -606,7 +606,7 @@ func (d *Database) getResponseWithPDUsForCompleteSync(
|
||||||
// a consistent view of the database throughout. This includes extracting the sync position.
|
// 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,
|
// 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.
|
// 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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -1063,15 +1063,6 @@ func (d *Database) SendToDeviceUpdatesWaiting(
|
||||||
return count > 0, nil
|
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(
|
func (d *Database) StoreNewSendForDeviceMessage(
|
||||||
ctx context.Context, streamPos types.StreamPosition, userID, deviceID string, event gomatrixserverlib.SendToDeviceEvent,
|
ctx context.Context, streamPos types.StreamPosition, userID, deviceID string, event gomatrixserverlib.SendToDeviceEvent,
|
||||||
) (types.StreamPosition, error) {
|
) (types.StreamPosition, error) {
|
||||||
|
|
@ -1082,7 +1073,7 @@ func (d *Database) StoreNewSendForDeviceMessage(
|
||||||
// Delegate the database write task to the SendToDeviceWriter. It'll guarantee
|
// 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.
|
// 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 {
|
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),
|
ctx, txn, userID, deviceID, string(j),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -117,13 +117,14 @@ func (s *inviteEventsStatements) InsertInviteEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *inviteEventsStatements) DeleteInviteEvent(
|
func (s *inviteEventsStatements) DeleteInviteEvent(
|
||||||
ctx context.Context, inviteEventID string,
|
ctx context.Context, txn *sql.Tx, inviteEventID string,
|
||||||
) (types.StreamPosition, error) {
|
) (types.StreamPosition, error) {
|
||||||
streamPos, err := s.streamIDStatements.nextStreamID(ctx, nil)
|
streamPos, err := s.streamIDStatements.nextStreamID(ctx, txn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return streamPos, err
|
return streamPos, err
|
||||||
}
|
}
|
||||||
_, err = s.deleteInviteEventStmt.ExecContext(ctx, streamPos, inviteEventID)
|
stmt := sqlutil.TxStmt(txn, s.deleteInviteEventStmt)
|
||||||
|
_, err = stmt.ExecContext(ctx, streamPos, inviteEventID)
|
||||||
return streamPos, err
|
return streamPos, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ type AccountData interface {
|
||||||
|
|
||||||
type Invites interface {
|
type Invites interface {
|
||||||
InsertInviteEvent(ctx context.Context, txn *sql.Tx, inviteEvent gomatrixserverlib.HeaderedEvent) (streamPos types.StreamPosition, err error)
|
InsertInviteEvent(ctx context.Context, txn *sql.Tx, inviteEvent gomatrixserverlib.HeaderedEvent) (streamPos types.StreamPosition, err error)
|
||||||
DeleteInviteEvent(ctx context.Context, inviteEventID string) (types.StreamPosition, error)
|
DeleteInviteEvent(ctx context.Context, txn *sql.Tx, inviteEventID string) (types.StreamPosition, error)
|
||||||
// SelectInviteEventsInRange returns a map of room ID to invite events. If multiple invite/retired invites exist in the given range, return the latest value
|
// SelectInviteEventsInRange returns a map of room ID to invite events. If multiple invite/retired invites exist in the given range, return the latest value
|
||||||
// for the room.
|
// for the room.
|
||||||
SelectInviteEventsInRange(ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range) (invites map[string]gomatrixserverlib.HeaderedEvent, retired map[string]gomatrixserverlib.HeaderedEvent, err error)
|
SelectInviteEventsInRange(ctx context.Context, txn *sql.Tx, targetUserID string, r types.Range) (invites map[string]gomatrixserverlib.HeaderedEvent, retired map[string]gomatrixserverlib.HeaderedEvent, err error)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue