Fix Forget Room bug that prevented Room Deletion (#16)

- Fix membership Insert to ensure the OnConflict performs an Update if exists
- Fix type in the rooms bulkSelectRoomNIDsSQL

Co-authored-by: alexf@example.com <alexf@example.com>
This commit is contained in:
alexfca 2021-09-13 09:52:55 +10:00 committed by GitHub
parent fd7f25479b
commit 032ad5b052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -297,13 +297,23 @@ func (s *membershipStatements) InsertMembership(
cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, dbCollectionName, docId) cosmosDocId := cosmosdbapi.GetDocumentId(s.db.cosmosConfig.TenantName, dbCollectionName, docId)
pk := cosmosdbapi.GetPartitionKey(s.db.cosmosConfig.TenantName, dbCollectionName) pk := cosmosdbapi.GetPartitionKey(s.db.cosmosConfig.TenantName, dbCollectionName)
// " ON CONFLICT DO NOTHING"
exists, _ := getMembership(s, ctx, pk, cosmosDocId)
if exists != nil {
exists.Membership.RoomNID = int64(roomNID)
exists.Membership.TargetNID = int64(targetUserNID)
exists.Membership.TargetLocal = localTarget
_, errSet := setMembership(s, ctx, *exists)
return errSet
}
data := MembershipCosmos{ data := MembershipCosmos{
EventNID: 0, EventNID: 0,
Forgotten: false, Forgotten: false,
MembershipNID: 1, MembershipNID: 1,
RoomNID: int64(roomNID), RoomNID: int64(roomNID),
SenderNID: 0, SenderNID: 0,
TargetLocal: false, TargetLocal: localTarget,
TargetNID: int64(targetUserNID), TargetNID: int64(targetUserNID),
} }

View file

@ -104,7 +104,7 @@ const bulkSelectRoomIDsSQL = "" +
// "SELECT room_nid FROM roomserver_rooms WHERE room_id IN ($1)" // "SELECT room_nid FROM roomserver_rooms WHERE room_id IN ($1)"
const bulkSelectRoomNIDsSQL = "" + const bulkSelectRoomNIDsSQL = "" +
"select * from c where c._cn = @x1 " + "select * from c where c._cn = @x1 " +
"and ARRAY_CONTAINS(@x2, c.mx_roomserver_room.room_nid)" "and ARRAY_CONTAINS(@x2, c.mx_roomserver_room.room_id)"
type roomStatements struct { type roomStatements struct {
db *Database db *Database