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
|
// panic rather than continue with an inconsistent database
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"event": string(msg.Event.JSON()),
|
"event": string(msg.Event.JSON()),
|
||||||
|
"pdupos": pduPos,
|
||||||
log.ErrorKey: err,
|
log.ErrorKey: err,
|
||||||
}).Panicf("roomserver output log: write invite failure")
|
}).Panicf("roomserver output log: write invite failure")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,6 @@ const insertInviteEventSQL = "" +
|
||||||
" (room_id, event_id, target_user_id, event_json)" +
|
" (room_id, event_id, target_user_id, event_json)" +
|
||||||
" VALUES ($1, $2, $3, $4)"
|
" VALUES ($1, $2, $3, $4)"
|
||||||
|
|
||||||
const selectLastInsertedInviteEventSQL = "" +
|
|
||||||
"SELECT id FROM syncapi_invite_events WHERE rowid = last_insert_rowid()"
|
|
||||||
|
|
||||||
const deleteInviteEventSQL = "" +
|
const deleteInviteEventSQL = "" +
|
||||||
"DELETE FROM syncapi_invite_events WHERE event_id = $1"
|
"DELETE FROM syncapi_invite_events WHERE event_id = $1"
|
||||||
|
|
||||||
|
|
@ -57,12 +54,11 @@ const selectMaxInviteIDSQL = "" +
|
||||||
"SELECT MAX(id) FROM syncapi_invite_events"
|
"SELECT MAX(id) FROM syncapi_invite_events"
|
||||||
|
|
||||||
type inviteEventsStatements struct {
|
type inviteEventsStatements struct {
|
||||||
streamIDStatements *streamIDStatements
|
streamIDStatements *streamIDStatements
|
||||||
insertInviteEventStmt *sql.Stmt
|
insertInviteEventStmt *sql.Stmt
|
||||||
selectLastInsertedInviteEventStmt *sql.Stmt
|
selectInviteEventsInRangeStmt *sql.Stmt
|
||||||
selectInviteEventsInRangeStmt *sql.Stmt
|
deleteInviteEventStmt *sql.Stmt
|
||||||
deleteInviteEventStmt *sql.Stmt
|
selectMaxInviteIDStmt *sql.Stmt
|
||||||
selectMaxInviteIDStmt *sql.Stmt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *inviteEventsStatements) prepare(db *sql.DB, streamID *streamIDStatements) (err error) {
|
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 {
|
if s.insertInviteEventStmt, err = db.Prepare(insertInviteEventSQL); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s.selectLastInsertedInviteEventStmt, err = db.Prepare(selectLastInsertedInviteEventSQL); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if s.selectInviteEventsInRangeStmt, err = db.Prepare(selectInviteEventsInRangeSQL); err != nil {
|
if s.selectInviteEventsInRangeStmt, err = db.Prepare(selectInviteEventsInRangeSQL); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +85,8 @@ func (s *inviteEventsStatements) prepare(db *sql.DB, streamID *streamIDStatement
|
||||||
func (s *inviteEventsStatements) insertInviteEvent(
|
func (s *inviteEventsStatements) insertInviteEvent(
|
||||||
ctx context.Context, inviteEvent gomatrixserverlib.Event,
|
ctx context.Context, inviteEvent gomatrixserverlib.Event,
|
||||||
) (streamPos types.StreamPosition, err error) {
|
) (streamPos types.StreamPosition, err error) {
|
||||||
_, err = s.insertInviteEventStmt.ExecContext(
|
var res sql.Result
|
||||||
|
res, err = s.insertInviteEventStmt.ExecContext(
|
||||||
ctx,
|
ctx,
|
||||||
inviteEvent.RoomID(),
|
inviteEvent.RoomID(),
|
||||||
inviteEvent.EventID(),
|
inviteEvent.EventID(),
|
||||||
|
|
@ -102,7 +96,12 @@ func (s *inviteEventsStatements) insertInviteEvent(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = s.selectLastInsertedInviteEventStmt.QueryRowContext(ctx).Scan(&streamPos)
|
var rowID int64
|
||||||
|
rowID, err = res.LastInsertId()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
streamPos = types.StreamPosition(rowID)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue