mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 06:12:45 +00:00
More sane next batch handling, typing notification tweaks, give invites their own stream position, device list fix (#1641)
* Update sync responses * Fix positions, add ApplyUpdates * Fix MarshalText as non-pointer, PrevBatch is optional * Increment by number of read receipts * Merge branch 'master' into neilalexander/devicelist * Tweak typing * Include keyserver position tweak * Fix typing next position in all cases * Tweaks * Fix typo * Tweaks, restore StreamingToken.MarshalText which somehow went missing? * Rely on positions from notifier rather than manually advancing them * Revert "Rely on positions from notifier rather than manually advancing them" This reverts commit 53112a62cc3bfd9989acab518e69eeb27938117a. * Give invites their own position, fix other things * Fix test * Fix invites maybe * Un-whitelist tests that look to be genuinely wrong * Use real receipt positions * Ensure send-to-device uses real positions too
This commit is contained in:
parent
a518e2971a
commit
50963b724b
22 changed files with 228 additions and 152 deletions
|
@ -51,7 +51,7 @@ const upsertReceipt = "" +
|
|||
" DO UPDATE SET id = $7, event_id = $8, receipt_ts = $9"
|
||||
|
||||
const selectRoomReceipts = "" +
|
||||
"SELECT room_id, receipt_type, user_id, event_id, receipt_ts" +
|
||||
"SELECT id, room_id, receipt_type, user_id, event_id, receipt_ts" +
|
||||
" FROM syncapi_receipts" +
|
||||
" WHERE id > $1 and room_id in ($2)"
|
||||
|
||||
|
@ -99,9 +99,9 @@ func (r *receiptStatements) UpsertReceipt(ctx context.Context, txn *sql.Tx, room
|
|||
}
|
||||
|
||||
// SelectRoomReceiptsAfter select all receipts for a given room after a specific timestamp
|
||||
func (r *receiptStatements) SelectRoomReceiptsAfter(ctx context.Context, roomIDs []string, streamPos types.StreamPosition) ([]api.OutputReceiptEvent, error) {
|
||||
func (r *receiptStatements) SelectRoomReceiptsAfter(ctx context.Context, roomIDs []string, streamPos types.StreamPosition) (types.StreamPosition, []api.OutputReceiptEvent, error) {
|
||||
selectSQL := strings.Replace(selectRoomReceipts, "($2)", sqlutil.QueryVariadicOffset(len(roomIDs), 1), 1)
|
||||
|
||||
lastPos := types.StreamPosition(0)
|
||||
params := make([]interface{}, len(roomIDs)+1)
|
||||
params[0] = streamPos
|
||||
for k, v := range roomIDs {
|
||||
|
@ -109,19 +109,23 @@ func (r *receiptStatements) SelectRoomReceiptsAfter(ctx context.Context, roomIDs
|
|||
}
|
||||
rows, err := r.db.QueryContext(ctx, selectSQL, params...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to query room receipts: %w", err)
|
||||
return 0, nil, fmt.Errorf("unable to query room receipts: %w", err)
|
||||
}
|
||||
defer internal.CloseAndLogIfError(ctx, rows, "SelectRoomReceiptsAfter: rows.close() failed")
|
||||
var res []api.OutputReceiptEvent
|
||||
for rows.Next() {
|
||||
r := api.OutputReceiptEvent{}
|
||||
err = rows.Scan(&r.RoomID, &r.Type, &r.UserID, &r.EventID, &r.Timestamp)
|
||||
var id types.StreamPosition
|
||||
err = rows.Scan(&id, &r.RoomID, &r.Type, &r.UserID, &r.EventID, &r.Timestamp)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("unable to scan row to api.Receipts: %w", err)
|
||||
return 0, res, fmt.Errorf("unable to scan row to api.Receipts: %w", err)
|
||||
}
|
||||
res = append(res, r)
|
||||
if id > lastPos {
|
||||
lastPos = id
|
||||
}
|
||||
}
|
||||
return res, rows.Err()
|
||||
return lastPos, res, rows.Err()
|
||||
}
|
||||
|
||||
func (s *receiptStatements) SelectMaxReceiptID(
|
||||
|
|
|
@ -100,8 +100,14 @@ func NewSqliteSendToDeviceTable(db *sql.DB) (tables.SendToDevice, error) {
|
|||
|
||||
func (s *sendToDeviceStatements) InsertSendToDeviceMessage(
|
||||
ctx context.Context, txn *sql.Tx, userID, deviceID, content string,
|
||||
) (err error) {
|
||||
_, err = sqlutil.TxStmt(txn, s.insertSendToDeviceMessageStmt).ExecContext(ctx, userID, deviceID, content)
|
||||
) (pos types.StreamPosition, err error) {
|
||||
var result sql.Result
|
||||
result, err = sqlutil.TxStmt(txn, s.insertSendToDeviceMessageStmt).ExecContext(ctx, userID, deviceID, content)
|
||||
if p, err := result.LastInsertId(); err != nil {
|
||||
return 0, err
|
||||
} else {
|
||||
pos = types.StreamPosition(p)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -117,7 +123,7 @@ func (s *sendToDeviceStatements) CountSendToDeviceMessages(
|
|||
|
||||
func (s *sendToDeviceStatements) SelectSendToDeviceMessages(
|
||||
ctx context.Context, txn *sql.Tx, userID, deviceID string,
|
||||
) (events []types.SendToDeviceEvent, err error) {
|
||||
) (lastPos types.StreamPosition, events []types.SendToDeviceEvent, err error) {
|
||||
rows, err := sqlutil.TxStmt(txn, s.selectSendToDeviceMessagesStmt).QueryContext(ctx, userID, deviceID)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -145,9 +151,12 @@ func (s *sendToDeviceStatements) SelectSendToDeviceMessages(
|
|||
}
|
||||
}
|
||||
events = append(events, event)
|
||||
if types.StreamPosition(id) > lastPos {
|
||||
lastPos = types.StreamPosition(id)
|
||||
}
|
||||
}
|
||||
|
||||
return events, rows.Err()
|
||||
return lastPos, events, rows.Err()
|
||||
}
|
||||
|
||||
func (s *sendToDeviceStatements) UpdateSentSendToDeviceMessages(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue