diff --git a/roomserver/storage/postgres/rooms_table.go b/roomserver/storage/postgres/rooms_table.go index 994399532..7b24bd192 100644 --- a/roomserver/storage/postgres/rooms_table.go +++ b/roomserver/storage/postgres/rooms_table.go @@ -155,8 +155,7 @@ func (s *roomStatements) SelectRoomInfo(ctx context.Context, txn *sql.Tx, roomID if err == sql.ErrNoRows { return nil, nil } - info.SetStateSnapshotNID(stateSnapshotNID) - info.SetIsStub(len(latestNIDs) == 0) + info.Update(stateSnapshotNID, len(latestNIDs) == 0) return &info, err } diff --git a/roomserver/storage/shared/room_updater.go b/roomserver/storage/shared/room_updater.go index 42c0c8f2d..cd841ab4f 100644 --- a/roomserver/storage/shared/room_updater.go +++ b/roomserver/storage/shared/room_updater.go @@ -176,10 +176,6 @@ func (u *RoomUpdater) EventStateKeyNIDs( return u.d.eventStateKeyNIDs(ctx, u.txn, eventStateKeys) } -func (u *RoomUpdater) RoomInfo(ctx context.Context, roomID string) (*types.RoomInfo, error) { - return u.d.roomInfo(ctx, u.txn, roomID) -} - func (u *RoomUpdater) EventIDs( ctx context.Context, eventNIDs []types.EventNID, ) (map[types.EventNID]string, error) { @@ -237,10 +233,7 @@ func (u *RoomUpdater) SetLatestEvents( // 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. - if u.roomInfo != nil { - u.roomInfo.SetStateSnapshotNID(currentStateSnapshotNID) - u.roomInfo.SetIsStub(false) - } + u.roomInfo.Update(currentStateSnapshotNID, len(eventNIDs) == 0) return nil }) } diff --git a/roomserver/storage/shared/storage.go b/roomserver/storage/shared/storage.go index 9e6a4142c..306805a53 100644 --- a/roomserver/storage/shared/storage.go +++ b/roomserver/storage/shared/storage.go @@ -170,14 +170,17 @@ func (d *Database) roomInfo(ctx context.Context, txn *sql.Tx, roomID string) (*t // If we have a stubby cache entry already, update it and return // the reference to the cache entry. if roomInfo != nil { - roomInfo.CopyFrom(roomInfoFromDB) + roomInfo.Update( + roomInfoFromDB.StateSnapshotNID(), + roomInfoFromDB.IsStub(), + ) return roomInfo, nil } // Otherwise, try to admit the data into the cache and return the // new reference from the database. if roomInfoFromDB != nil { - d.Cache.StoreRoomServerRoomID(roomInfoFromDB.RoomNID, roomID) d.Cache.StoreRoomInfo(roomID, roomInfoFromDB) + d.Cache.StoreRoomServerRoomID(roomInfoFromDB.RoomNID, roomID) } return roomInfoFromDB, err } diff --git a/roomserver/storage/sqlite3/rooms_table.go b/roomserver/storage/sqlite3/rooms_table.go index 25b611b3e..2ac55cd00 100644 --- a/roomserver/storage/sqlite3/rooms_table.go +++ b/roomserver/storage/sqlite3/rooms_table.go @@ -144,8 +144,7 @@ func (s *roomStatements) SelectRoomInfo(ctx context.Context, txn *sql.Tx, roomID if err = json.Unmarshal([]byte(latestNIDsJSON), &latestNIDs); err != nil { return nil, err } - info.SetStateSnapshotNID(stateSnapshotNID) - info.SetIsStub(len(latestNIDs) == 0) + info.Update(stateSnapshotNID, len(latestNIDs) == 0) return &info, err } diff --git a/roomserver/storage/tables/rooms_table_test.go b/roomserver/storage/tables/rooms_table_test.go index eddd012c8..004331885 100644 --- a/roomserver/storage/tables/rooms_table_test.go +++ b/roomserver/storage/tables/rooms_table_test.go @@ -67,7 +67,7 @@ func TestRoomsTable(t *testing.T) { RoomNID: wantRoomNID, RoomVersion: room.Version, } - expected.SetIsStub(true) // there are no latestEventNIDs + expected.Update(0, true) // there are no latestEventNIDs assert.Equal(t, expected, roomInfo) roomInfo, err = tab.SelectRoomInfo(ctx, nil, "!doesnotexist:localhost") @@ -107,7 +107,7 @@ func TestRoomsTable(t *testing.T) { RoomNID: wantRoomNID, RoomVersion: room.Version, } - expected.SetStateSnapshotNID(1) + expected.Update(1, false) assert.Equal(t, expected, roomInfo) eventNIDs, snapshotNID, err := tab.SelectLatestEventNIDs(ctx, nil, wantRoomNID) diff --git a/roomserver/types/types.go b/roomserver/types/types.go index f40980994..a05e94fe0 100644 --- a/roomserver/types/types.go +++ b/roomserver/types/types.go @@ -299,27 +299,10 @@ func (r *RoomInfo) IsStub() bool { return r.isStub } -func (r *RoomInfo) SetStateSnapshotNID(nid StateSnapshotNID) { +func (r *RoomInfo) Update(nid StateSnapshotNID, isStub bool) { r.mu.Lock() defer r.mu.Unlock() - r.stateSnapshotNID = nid -} -func (r *RoomInfo) SetIsStub(isStub bool) { - r.mu.Lock() - defer r.mu.Unlock() + r.stateSnapshotNID = nid r.isStub = isStub } - -func (r *RoomInfo) CopyFrom(r2 *RoomInfo) { - r.mu.Lock() - defer r.mu.Unlock() - - r2.mu.RLock() - defer r2.mu.RUnlock() - - r.RoomNID = r2.RoomNID - r.RoomVersion = r2.RoomVersion - r.stateSnapshotNID = r2.stateSnapshotNID - r.isStub = r2.isStub -}