mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 11:23:11 -06:00
bugfix: fix panic on new invite events from sytest
I'm unsure why the previous code didn't work, but it's clearer, quicker and easier to read the `LastInsertID()` way. Previously, the code would panic as the SELECT would fail to find the last inserted row ID.
This commit is contained in:
parent
3dabf4d4ed
commit
f23fc25be0
|
|
@ -158,6 +158,7 @@ func (s *OutputRoomEventConsumer) onNewInviteEvent(
|
|||
// panic rather than continue with an inconsistent database
|
||||
log.WithFields(log.Fields{
|
||||
"event": string(msg.Event.JSON()),
|
||||
"pdupos": pduPos,
|
||||
log.ErrorKey: err,
|
||||
}).Panicf("roomserver output log: write invite failure")
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -42,9 +42,6 @@ const insertInviteEventSQL = "" +
|
|||
" (room_id, event_id, target_user_id, event_json)" +
|
||||
" VALUES ($1, $2, $3, $4)"
|
||||
|
||||
const selectLastInsertedInviteEventSQL = "" +
|
||||
"SELECT id FROM syncapi_invite_events WHERE rowid = last_insert_rowid()"
|
||||
|
||||
const deleteInviteEventSQL = "" +
|
||||
"DELETE FROM syncapi_invite_events WHERE event_id = $1"
|
||||
|
||||
|
|
@ -57,12 +54,11 @@ const selectMaxInviteIDSQL = "" +
|
|||
"SELECT MAX(id) FROM syncapi_invite_events"
|
||||
|
||||
type inviteEventsStatements struct {
|
||||
streamIDStatements *streamIDStatements
|
||||
insertInviteEventStmt *sql.Stmt
|
||||
selectLastInsertedInviteEventStmt *sql.Stmt
|
||||
selectInviteEventsInRangeStmt *sql.Stmt
|
||||
deleteInviteEventStmt *sql.Stmt
|
||||
selectMaxInviteIDStmt *sql.Stmt
|
||||
streamIDStatements *streamIDStatements
|
||||
insertInviteEventStmt *sql.Stmt
|
||||
selectInviteEventsInRangeStmt *sql.Stmt
|
||||
deleteInviteEventStmt *sql.Stmt
|
||||
selectMaxInviteIDStmt *sql.Stmt
|
||||
}
|
||||
|
||||
func (s *inviteEventsStatements) prepare(db *sql.DB, streamID *streamIDStatements) (err error) {
|
||||
|
|
@ -74,9 +70,6 @@ func (s *inviteEventsStatements) prepare(db *sql.DB, streamID *streamIDStatement
|
|||
if s.insertInviteEventStmt, err = db.Prepare(insertInviteEventSQL); err != nil {
|
||||
return
|
||||
}
|
||||
if s.selectLastInsertedInviteEventStmt, err = db.Prepare(selectLastInsertedInviteEventSQL); err != nil {
|
||||
return
|
||||
}
|
||||
if s.selectInviteEventsInRangeStmt, err = db.Prepare(selectInviteEventsInRangeSQL); err != nil {
|
||||
return
|
||||
}
|
||||
|
|
@ -92,7 +85,8 @@ func (s *inviteEventsStatements) prepare(db *sql.DB, streamID *streamIDStatement
|
|||
func (s *inviteEventsStatements) insertInviteEvent(
|
||||
ctx context.Context, inviteEvent gomatrixserverlib.Event,
|
||||
) (streamPos types.StreamPosition, err error) {
|
||||
_, err = s.insertInviteEventStmt.ExecContext(
|
||||
var res sql.Result
|
||||
res, err = s.insertInviteEventStmt.ExecContext(
|
||||
ctx,
|
||||
inviteEvent.RoomID(),
|
||||
inviteEvent.EventID(),
|
||||
|
|
@ -102,7 +96,12 @@ func (s *inviteEventsStatements) insertInviteEvent(
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = s.selectLastInsertedInviteEventStmt.QueryRowContext(ctx).Scan(&streamPos)
|
||||
var rowID int64
|
||||
rowID, err = res.LastInsertId()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
streamPos = types.StreamPosition(rowID)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue