aboutsummaryrefslogtreecommitdiff
path: root/roomserver/storage/shared
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-07-13 10:13:34 +0100
committerNeil Alexander <neilalexander@users.noreply.github.com>2022-07-13 10:13:34 +0100
commita1f9b02edfd56809eaedd04fd233b1828085e190 (patch)
treedc48e75fcc7244230c5004c1df69d5be0a571329 /roomserver/storage/shared
parent9cd8e9d4b97c6cff66665f57065a5bb8b7144045 (diff)
Pointerise `types.RoomInfo` in the cache so we can update it in-place in the latest events updater
Diffstat (limited to 'roomserver/storage/shared')
-rw-r--r--roomserver/storage/shared/room_updater.go13
-rw-r--r--roomserver/storage/shared/storage.go6
2 files changed, 9 insertions, 10 deletions
diff --git a/roomserver/storage/shared/room_updater.go b/roomserver/storage/shared/room_updater.go
index 8f4e011b..c35ac653 100644
--- a/roomserver/storage/shared/room_updater.go
+++ b/roomserver/storage/shared/room_updater.go
@@ -225,13 +225,12 @@ func (u *RoomUpdater) SetLatestEvents(
if err := u.d.RoomsTable.UpdateLatestEventNIDs(u.ctx, txn, roomNID, eventNIDs, lastEventNIDSent, currentStateSnapshotNID); err != nil {
return fmt.Errorf("u.d.RoomsTable.updateLatestEventNIDs: %w", err)
}
- if roomID, ok := u.d.Cache.GetRoomServerRoomID(roomNID); ok {
- if roomInfo, ok := u.d.Cache.GetRoomInfo(roomID); ok {
- roomInfo.StateSnapshotNID = currentStateSnapshotNID
- roomInfo.IsStub = false
- u.d.Cache.StoreRoomInfo(roomID, roomInfo)
- }
- }
+
+ // Since it's entirely possible that this types.RoomInfo came from the
+ // cache, we should make sure to update that entry so that the next run
+ // works from live data.
+ u.roomInfo.StateSnapshotNID = currentStateSnapshotNID
+ u.roomInfo.IsStub = false
return nil
})
}
diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go
index 692af1f6..d8d5f67c 100644
--- a/roomserver/storage/shared/storage.go
+++ b/roomserver/storage/shared/storage.go
@@ -139,13 +139,13 @@ func (d *Database) RoomInfo(ctx context.Context, roomID string) (*types.RoomInfo
}
func (d *Database) roomInfo(ctx context.Context, txn *sql.Tx, roomID string) (*types.RoomInfo, error) {
- if roomInfo, ok := d.Cache.GetRoomInfo(roomID); ok {
- return &roomInfo, nil
+ if roomInfo, ok := d.Cache.GetRoomInfo(roomID); ok && roomInfo != nil {
+ return roomInfo, nil
}
roomInfo, err := d.RoomsTable.SelectRoomInfo(ctx, txn, roomID)
if err == nil && roomInfo != nil {
d.Cache.StoreRoomServerRoomID(roomInfo.RoomNID, roomID)
- d.Cache.StoreRoomInfo(roomID, *roomInfo)
+ d.Cache.StoreRoomInfo(roomID, roomInfo)
}
return roomInfo, err
}