mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Add RoomInfo metadata struct (#1367)
* Add RoomInfo struct * Remove RoomNID and replace with RoomInfo * Bugfix and remove another needless query * nil guard
This commit is contained in:
parent
0ab5bccd11
commit
6d79f04354
10 changed files with 106 additions and 85 deletions
|
@ -120,6 +120,10 @@ func (d *Database) StateEntriesForTuples(
|
|||
)
|
||||
}
|
||||
|
||||
func (d *Database) RoomInfo(ctx context.Context, roomID string) (*types.RoomInfo, error) {
|
||||
return d.RoomsTable.SelectRoomInfo(ctx, roomID)
|
||||
}
|
||||
|
||||
func (d *Database) AddState(
|
||||
ctx context.Context,
|
||||
roomNID types.RoomNID,
|
||||
|
@ -194,34 +198,6 @@ func (d *Database) EventsFromIDs(ctx context.Context, eventIDs []string) ([]type
|
|||
return d.Events(ctx, nids)
|
||||
}
|
||||
|
||||
func (d *Database) RoomNID(ctx context.Context, roomID string) (types.RoomNID, error) {
|
||||
if nid, ok := d.Cache.GetRoomServerRoomNID(roomID); ok {
|
||||
return nid, nil
|
||||
}
|
||||
roomNID, err := d.RoomsTable.SelectRoomNID(ctx, nil, roomID)
|
||||
if err == sql.ErrNoRows {
|
||||
return 0, nil
|
||||
}
|
||||
d.Cache.StoreRoomServerRoomNID(roomID, roomNID)
|
||||
return roomNID, err
|
||||
}
|
||||
|
||||
func (d *Database) RoomNIDExcludingStubs(ctx context.Context, roomID string) (roomNID types.RoomNID, err error) {
|
||||
roomNID, err = d.RoomNID(ctx, roomID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
latestEvents, _, err := d.RoomsTable.SelectLatestEventNIDs(ctx, nil, roomNID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(latestEvents) == 0 {
|
||||
roomNID = 0
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Database) LatestEventIDs(
|
||||
ctx context.Context, roomNID types.RoomNID,
|
||||
) (references []gomatrixserverlib.EventReference, currentStateSnapshotNID types.StateSnapshotNID, depth int64, err error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue