mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-09 07:03:10 -06:00
Tweak roominfo some more
This commit is contained in:
parent
ac2dbb3513
commit
8543e24a57
|
|
@ -155,8 +155,7 @@ func (s *roomStatements) SelectRoomInfo(ctx context.Context, txn *sql.Tx, roomID
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
info.SetStateSnapshotNID(stateSnapshotNID)
|
info.Update(stateSnapshotNID, len(latestNIDs) == 0)
|
||||||
info.SetIsStub(len(latestNIDs) == 0)
|
|
||||||
return &info, err
|
return &info, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -176,10 +176,6 @@ func (u *RoomUpdater) EventStateKeyNIDs(
|
||||||
return u.d.eventStateKeyNIDs(ctx, u.txn, eventStateKeys)
|
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(
|
func (u *RoomUpdater) EventIDs(
|
||||||
ctx context.Context, eventNIDs []types.EventNID,
|
ctx context.Context, eventNIDs []types.EventNID,
|
||||||
) (map[types.EventNID]string, error) {
|
) (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
|
// 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
|
// cache, we should make sure to update that entry so that the next run
|
||||||
// works from live data.
|
// works from live data.
|
||||||
if u.roomInfo != nil {
|
u.roomInfo.Update(currentStateSnapshotNID, len(eventNIDs) == 0)
|
||||||
u.roomInfo.SetStateSnapshotNID(currentStateSnapshotNID)
|
|
||||||
u.roomInfo.SetIsStub(false)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
// If we have a stubby cache entry already, update it and return
|
||||||
// the reference to the cache entry.
|
// the reference to the cache entry.
|
||||||
if roomInfo != nil {
|
if roomInfo != nil {
|
||||||
roomInfo.CopyFrom(roomInfoFromDB)
|
roomInfo.Update(
|
||||||
|
roomInfoFromDB.StateSnapshotNID(),
|
||||||
|
roomInfoFromDB.IsStub(),
|
||||||
|
)
|
||||||
return roomInfo, nil
|
return roomInfo, nil
|
||||||
}
|
}
|
||||||
// Otherwise, try to admit the data into the cache and return the
|
// Otherwise, try to admit the data into the cache and return the
|
||||||
// new reference from the database.
|
// new reference from the database.
|
||||||
if roomInfoFromDB != nil {
|
if roomInfoFromDB != nil {
|
||||||
d.Cache.StoreRoomServerRoomID(roomInfoFromDB.RoomNID, roomID)
|
|
||||||
d.Cache.StoreRoomInfo(roomID, roomInfoFromDB)
|
d.Cache.StoreRoomInfo(roomID, roomInfoFromDB)
|
||||||
|
d.Cache.StoreRoomServerRoomID(roomInfoFromDB.RoomNID, roomID)
|
||||||
}
|
}
|
||||||
return roomInfoFromDB, err
|
return roomInfoFromDB, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,7 @@ func (s *roomStatements) SelectRoomInfo(ctx context.Context, txn *sql.Tx, roomID
|
||||||
if err = json.Unmarshal([]byte(latestNIDsJSON), &latestNIDs); err != nil {
|
if err = json.Unmarshal([]byte(latestNIDsJSON), &latestNIDs); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
info.SetStateSnapshotNID(stateSnapshotNID)
|
info.Update(stateSnapshotNID, len(latestNIDs) == 0)
|
||||||
info.SetIsStub(len(latestNIDs) == 0)
|
|
||||||
return &info, err
|
return &info, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ func TestRoomsTable(t *testing.T) {
|
||||||
RoomNID: wantRoomNID,
|
RoomNID: wantRoomNID,
|
||||||
RoomVersion: room.Version,
|
RoomVersion: room.Version,
|
||||||
}
|
}
|
||||||
expected.SetIsStub(true) // there are no latestEventNIDs
|
expected.Update(0, true) // there are no latestEventNIDs
|
||||||
assert.Equal(t, expected, roomInfo)
|
assert.Equal(t, expected, roomInfo)
|
||||||
|
|
||||||
roomInfo, err = tab.SelectRoomInfo(ctx, nil, "!doesnotexist:localhost")
|
roomInfo, err = tab.SelectRoomInfo(ctx, nil, "!doesnotexist:localhost")
|
||||||
|
|
@ -107,7 +107,7 @@ func TestRoomsTable(t *testing.T) {
|
||||||
RoomNID: wantRoomNID,
|
RoomNID: wantRoomNID,
|
||||||
RoomVersion: room.Version,
|
RoomVersion: room.Version,
|
||||||
}
|
}
|
||||||
expected.SetStateSnapshotNID(1)
|
expected.Update(1, false)
|
||||||
assert.Equal(t, expected, roomInfo)
|
assert.Equal(t, expected, roomInfo)
|
||||||
|
|
||||||
eventNIDs, snapshotNID, err := tab.SelectLatestEventNIDs(ctx, nil, wantRoomNID)
|
eventNIDs, snapshotNID, err := tab.SelectLatestEventNIDs(ctx, nil, wantRoomNID)
|
||||||
|
|
|
||||||
|
|
@ -299,27 +299,10 @@ func (r *RoomInfo) IsStub() bool {
|
||||||
return r.isStub
|
return r.isStub
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RoomInfo) SetStateSnapshotNID(nid StateSnapshotNID) {
|
func (r *RoomInfo) Update(nid StateSnapshotNID, isStub bool) {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
r.stateSnapshotNID = nid
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RoomInfo) SetIsStub(isStub bool) {
|
r.stateSnapshotNID = nid
|
||||||
r.mu.Lock()
|
|
||||||
defer r.mu.Unlock()
|
|
||||||
r.isStub = isStub
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue