A batch of useful comments

pulled out of #329
This commit is contained in:
David Robertson 2023-10-19 14:17:39 +01:00
parent 867cf68a20
commit 84a5ae5dc4
No known key found for this signature in database
GPG Key ID: 903ECE108A39DEDD
3 changed files with 16 additions and 2 deletions

View File

@ -130,6 +130,7 @@ type V2ExpiredToken struct {
func (*V2ExpiredToken) Type() string { return "V2ExpiredToken" }
// V2InvalidateRoom is emitted after a non-incremental state change to a room.
type V2InvalidateRoom struct {
RoomID string
}

View File

@ -644,6 +644,11 @@ func (s *Storage) RoomStateAfterEventPosition(ctx context.Context, roomIDs []str
return
}
// LatestEventsInRooms returns the most recent events
// - in the given rooms
// - that the user has permission to see
// - with NIDs <= `to`.
// Up to `limit` events are chosen per room.
func (s *Storage) LatestEventsInRooms(userID string, roomIDs []string, to int64, limit int) (map[string]*LatestEvents, error) {
roomIDToRanges, err := s.visibleEventNIDsBetweenForRooms(userID, roomIDs, 0, to)
if err != nil {
@ -697,6 +702,9 @@ func (s *Storage) LatestEventsInRooms(userID string, roomIDs []string, to int64,
return result, err
}
// visibleEventNIDsBetweenForRooms determines which events a given user has permission to see.
// It accepts a nid range [from, to]. For each given room, it calculates the NID ranges
// [A1, B1], [A2, B2], ... within [from, to] in which the user has permission to see events.
func (s *Storage) visibleEventNIDsBetweenForRooms(userID string, roomIDs []string, from, to int64) (map[string][][2]int64, error) {
// load *THESE* joined rooms for this user at from (inclusive)
var membershipEvents []Event

View File

@ -54,6 +54,7 @@ type UserRoomData struct {
// avatar (if any) as specified in their membership event in that room.
ResolvedAvatarURL string
// Spaces is the set of room IDs of spaces that this room is part of.
Spaces map[string]struct{}
// Map of tag to order float.
// See https://spec.matrix.org/latest/client-server-api/#room-tagging
@ -192,6 +193,8 @@ type UserCache struct {
}
func NewUserCache(userID string, globalCache *GlobalCache, store *state.Storage, txnIDs TransactionIDFetcher) *UserCache {
// see SyncLiveHandler.userCache for the initialisation proper, which works by
// firing off a bunch of OnBlahBlah callbacks.
uc := &UserCache{
UserID: userID,
roomToDataMu: &sync.RWMutex{},
@ -302,8 +305,10 @@ func (c *UserCache) OnRegistered(ctx context.Context) error {
return nil
}
// LazyLoadTimelines loads up to `maxTimelineEvents` from the database, plus other
// timeline-related data. Events from senders ignored by this user are dropped.
// LazyLoadTimelines loads the most recent timeline events (up to `maxTimelineEvents`)
// for each of the given rooms from the database (plus other timeline-related data).
// Only events with NID <= loadPos are returned.
// Events from senders ignored by this user are dropped.
// Returns nil on error.
func (c *UserCache) LazyLoadTimelines(ctx context.Context, loadPos int64, roomIDs []string, maxTimelineEvents int) map[string]state.LatestEvents {
_, span := internal.StartSpan(ctx, "LazyLoadTimelines")