aboutsummaryrefslogtreecommitdiff
path: root/roomserver
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-07-22 19:43:48 +0100
committerGitHub <noreply@github.com>2022-07-22 19:43:48 +0100
commitc7d978274d1e9606574106a9fee63ff555604d1d (patch)
treed1856e232c5482a1ceffb7d06350943fa0ff57ba /roomserver
parentf0c8a03649ab270bb15156a3cc47cae2aee3f36a (diff)
Try to fix HTTP 500s on `/members` (#2581)
Diffstat (limited to 'roomserver')
-rw-r--r--roomserver/internal/query/query.go7
-rw-r--r--roomserver/storage/postgres/membership_table.go10
-rw-r--r--roomserver/storage/sqlite3/membership_table.go10
-rw-r--r--roomserver/storage/tables/membership_table_test.go3
4 files changed, 20 insertions, 10 deletions
diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go
index da1b3253..f652a8ea 100644
--- a/roomserver/internal/query/query.go
+++ b/roomserver/internal/query/query.go
@@ -16,6 +16,7 @@ package query
import (
"context"
+ "database/sql"
"encoding/json"
"errors"
"fmt"
@@ -225,6 +226,9 @@ func (r *Queryer) QueryMembershipsForRoom(
var eventNIDs []types.EventNID
eventNIDs, err = r.DB.GetMembershipEventNIDsForRoom(ctx, info.RoomNID, request.JoinedOnly, request.LocalOnly)
if err != nil {
+ if err == sql.ErrNoRows {
+ return nil
+ }
return fmt.Errorf("r.DB.GetMembershipEventNIDsForRoom: %w", err)
}
events, err = r.DB.Events(ctx, eventNIDs)
@@ -260,6 +264,9 @@ func (r *Queryer) QueryMembershipsForRoom(
var eventNIDs []types.EventNID
eventNIDs, err = r.DB.GetMembershipEventNIDsForRoom(ctx, info.RoomNID, request.JoinedOnly, false)
if err != nil {
+ if err == sql.ErrNoRows {
+ return nil
+ }
return err
}
diff --git a/roomserver/storage/postgres/membership_table.go b/roomserver/storage/postgres/membership_table.go
index ee457393..eaaea22a 100644
--- a/roomserver/storage/postgres/membership_table.go
+++ b/roomserver/storage/postgres/membership_table.go
@@ -86,24 +86,24 @@ const insertMembershipSQL = "" +
const selectMembershipFromRoomAndTargetSQL = "" +
"SELECT membership_nid, event_nid, forgotten FROM roomserver_membership" +
- " WHERE room_nid = $1 AND target_nid = $2"
+ " WHERE room_nid = $1 AND event_nid != 0 AND target_nid = $2"
const selectMembershipsFromRoomAndMembershipSQL = "" +
"SELECT event_nid FROM roomserver_membership" +
- " WHERE room_nid = $1 AND membership_nid = $2 and forgotten = false"
+ " WHERE room_nid = $1 AND event_nid != 0 AND membership_nid = $2 and forgotten = false"
const selectLocalMembershipsFromRoomAndMembershipSQL = "" +
"SELECT event_nid FROM roomserver_membership" +
- " WHERE room_nid = $1 AND membership_nid = $2" +
+ " WHERE room_nid = $1 AND event_nid != 0 AND membership_nid = $2" +
" AND target_local = true and forgotten = false"
const selectMembershipsFromRoomSQL = "" +
"SELECT event_nid FROM roomserver_membership" +
- " WHERE room_nid = $1 and forgotten = false"
+ " WHERE room_nid = $1 AND event_nid != 0 and forgotten = false"
const selectLocalMembershipsFromRoomSQL = "" +
"SELECT event_nid FROM roomserver_membership" +
- " WHERE room_nid = $1" +
+ " WHERE room_nid = $1 AND event_nid != 0" +
" AND target_local = true and forgotten = false"
const selectMembershipForUpdateSQL = "" +
diff --git a/roomserver/storage/sqlite3/membership_table.go b/roomserver/storage/sqlite3/membership_table.go
index 00a9bd4f..9dda82fb 100644
--- a/roomserver/storage/sqlite3/membership_table.go
+++ b/roomserver/storage/sqlite3/membership_table.go
@@ -62,24 +62,24 @@ const insertMembershipSQL = "" +
const selectMembershipFromRoomAndTargetSQL = "" +
"SELECT membership_nid, event_nid, forgotten FROM roomserver_membership" +
- " WHERE room_nid = $1 AND target_nid = $2"
+ " WHERE room_nid = $1 AND event_nid != 0 AND target_nid = $2"
const selectMembershipsFromRoomAndMembershipSQL = "" +
"SELECT event_nid FROM roomserver_membership" +
- " WHERE room_nid = $1 AND membership_nid = $2 and forgotten = false"
+ " WHERE room_nid = $1 AND event_nid != 0 AND membership_nid = $2 and forgotten = false"
const selectLocalMembershipsFromRoomAndMembershipSQL = "" +
"SELECT event_nid FROM roomserver_membership" +
- " WHERE room_nid = $1 AND membership_nid = $2" +
+ " WHERE room_nid = $1 AND event_nid != 0 AND membership_nid = $2" +
" AND target_local = true and forgotten = false"
const selectMembershipsFromRoomSQL = "" +
"SELECT event_nid FROM roomserver_membership" +
- " WHERE room_nid = $1 and forgotten = false"
+ " WHERE room_nid = $1 AND event_nid != 0 and forgotten = false"
const selectLocalMembershipsFromRoomSQL = "" +
"SELECT event_nid FROM roomserver_membership" +
- " WHERE room_nid = $1" +
+ " WHERE room_nid = $1 AND event_nid != 0" +
" AND target_local = true and forgotten = false"
const selectMembershipForUpdateSQL = "" +
diff --git a/roomserver/storage/tables/membership_table_test.go b/roomserver/storage/tables/membership_table_test.go
index 14e8ce50..f789ef4a 100644
--- a/roomserver/storage/tables/membership_table_test.go
+++ b/roomserver/storage/tables/membership_table_test.go
@@ -60,6 +60,9 @@ func TestMembershipTable(t *testing.T) {
// This inserts a left user to the room
err = tab.InsertMembership(ctx, nil, 1, stateKeyNID, true)
assert.NoError(t, err)
+ // We must update the membership with a non-zero event NID or it will get filtered out in later queries
+ _, err = tab.UpdateMembership(ctx, nil, 1, stateKeyNID, userNIDs[0], tables.MembershipStateLeaveOrBan, 1, false)
+ assert.NoError(t, err)
}
// ... so this should be false