Change types.RoomInfo cache to *types.RoomInfo

This commit is contained in:
Neil Alexander 2022-07-12 15:05:12 +01:00
parent 09f0ff14c8
commit 9aa5ce1530
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 9 additions and 9 deletions

View file

@ -16,18 +16,18 @@ import (
// a room Info cache. It must only be used from the roomserver only // a room Info cache. It must only be used from the roomserver only
// It is not safe for use from other components. // It is not safe for use from other components.
type RoomInfoCache interface { type RoomInfoCache interface {
GetRoomInfo(roomID string) (roomInfo types.RoomInfo, ok bool) GetRoomInfo(roomID string) (roomInfo *types.RoomInfo, ok bool)
StoreRoomInfo(roomID string, roomInfo types.RoomInfo) StoreRoomInfo(roomID string, roomInfo *types.RoomInfo)
} }
// GetRoomInfo must only be called from the roomserver only. It is not // GetRoomInfo must only be called from the roomserver only. It is not
// safe for use from other components. // safe for use from other components.
func (c Caches) GetRoomInfo(roomID string) (types.RoomInfo, bool) { func (c Caches) GetRoomInfo(roomID string) (*types.RoomInfo, bool) {
return c.RoomInfos.Get(roomID) return c.RoomInfos.Get(roomID)
} }
// StoreRoomInfo must only be called from the roomserver only. It is not // StoreRoomInfo must only be called from the roomserver only. It is not
// safe for use from other components. // safe for use from other components.
func (c Caches) StoreRoomInfo(roomID string, roomInfo types.RoomInfo) { func (c Caches) StoreRoomInfo(roomID string, roomInfo *types.RoomInfo) {
c.RoomInfos.Set(roomID, roomInfo) c.RoomInfos.Set(roomID, roomInfo)
} }

View file

@ -28,7 +28,7 @@ type Caches struct {
RoomServerRoomNIDs Cache[string, types.RoomNID] // room ID -> room NID RoomServerRoomNIDs Cache[string, types.RoomNID] // room ID -> room NID
RoomServerRoomIDs Cache[int64, string] // room NID -> room ID RoomServerRoomIDs Cache[int64, string] // room NID -> room ID
RoomServerEvents Cache[int64, *gomatrixserverlib.Event] // event NID -> event RoomServerEvents Cache[int64, *gomatrixserverlib.Event] // event NID -> event
RoomInfos Cache[string, types.RoomInfo] // room ID -> room info RoomInfos Cache[string, *types.RoomInfo] // room ID -> room info
FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent] // queue NID -> PDU FederationPDUs Cache[int64, *gomatrixserverlib.HeaderedEvent] // queue NID -> PDU
FederationEDUs Cache[int64, *gomatrixserverlib.EDU] // queue NID -> EDU FederationEDUs Cache[int64, *gomatrixserverlib.EDU] // queue NID -> EDU
SpaceSummaryRooms Cache[string, gomatrixserverlib.MSC2946SpacesResponse] // room ID -> space response SpaceSummaryRooms Cache[string, gomatrixserverlib.MSC2946SpacesResponse] // room ID -> space response

View file

@ -100,7 +100,7 @@ func NewRistrettoCache(maxCost config.DataUnit, maxAge time.Duration, enableProm
MaxAge: maxAge, MaxAge: maxAge,
}, },
}, },
RoomInfos: &RistrettoCachePartition[string, types.RoomInfo]{ // room ID -> room info RoomInfos: &RistrettoCachePartition[string, *types.RoomInfo]{ // room ID -> room info
cache: cache, cache: cache,
Prefix: roomInfosCache, Prefix: roomInfosCache,
Mutable: true, Mutable: true,

View file

@ -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) { func (d *Database) roomInfo(ctx context.Context, txn *sql.Tx, roomID string) (*types.RoomInfo, error) {
if roomInfo, ok := d.Cache.GetRoomInfo(roomID); ok { if roomInfo, ok := d.Cache.GetRoomInfo(roomID); ok && roomInfo != nil {
return &roomInfo, nil return roomInfo, nil
} }
roomInfo, err := d.RoomsTable.SelectRoomInfo(ctx, txn, roomID) roomInfo, err := d.RoomsTable.SelectRoomInfo(ctx, txn, roomID)
if err == nil && roomInfo != nil { if err == nil && roomInfo != nil {
d.Cache.StoreRoomServerRoomID(roomInfo.RoomNID, roomID) d.Cache.StoreRoomServerRoomID(roomInfo.RoomNID, roomID)
d.Cache.StoreRoomInfo(roomID, *roomInfo) d.Cache.StoreRoomInfo(roomID, roomInfo)
} }
return roomInfo, err return roomInfo, err
} }