mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-01 13:52:46 +00:00
Get state deltas without filters (#2810)
This makes the following changes: - get state deltas without the user supplied filter, so we can actually "calculate" state transitions - closes `stmt` when using SQLite - Adds presence for users who newly joined a room, even if the syncing user already knows about the presence status (should fix https://github.com/matrix-org/complement/pull/516)
This commit is contained in:
parent
8cbe14bd6d
commit
e79bfd8fd5
9 changed files with 144 additions and 65 deletions
|
@ -5,10 +5,11 @@ import (
|
|||
"database/sql"
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/eventutil"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
type DatabaseTransaction struct {
|
||||
|
@ -277,6 +278,7 @@ func (d *DatabaseTransaction) GetBackwardTopologyPos(
|
|||
// exclusive of oldPos, inclusive of newPos, for the rooms in which
|
||||
// the user has new membership events.
|
||||
// A list of joined room IDs is also returned in case the caller needs it.
|
||||
// nolint:gocyclo
|
||||
func (d *DatabaseTransaction) GetStateDeltas(
|
||||
ctx context.Context, device *userapi.Device,
|
||||
r types.Range, userID string,
|
||||
|
@ -311,7 +313,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
|
|||
}
|
||||
|
||||
// get all the state events ever (i.e. for all available rooms) between these two positions
|
||||
stateNeeded, eventMap, err := d.OutputEvents.SelectStateInRange(ctx, d.txn, r, stateFilter, allRoomIDs)
|
||||
stateNeeded, eventMap, err := d.OutputEvents.SelectStateInRange(ctx, d.txn, r, nil, allRoomIDs)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil, nil
|
||||
|
@ -326,6 +328,22 @@ func (d *DatabaseTransaction) GetStateDeltas(
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
// get all the state events ever (i.e. for all available rooms) between these two positions
|
||||
stateNeededFiltered, eventMapFiltered, err := d.OutputEvents.SelectStateInRange(ctx, d.txn, r, stateFilter, allRoomIDs)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil, nil
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
stateFiltered, err := d.fetchStateEvents(ctx, d.txn, stateNeededFiltered, eventMapFiltered)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil, nil
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// find out which rooms this user is peeking, if any.
|
||||
// We do this before joins so any peeks get overwritten
|
||||
peeks, err := d.Peeks.SelectPeeksInRange(ctx, d.txn, userID, device.ID, r)
|
||||
|
@ -371,6 +389,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
|
|||
// If our membership is now join but the previous membership wasn't
|
||||
// then this is a "join transition", so we'll insert this room.
|
||||
if prevMembership != membership {
|
||||
newlyJoinedRooms[roomID] = true
|
||||
// Get the full room state, as we'll send that down for a newly
|
||||
// joined room instead of a delta.
|
||||
var s []types.StreamEvent
|
||||
|
@ -383,8 +402,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
|
|||
|
||||
// Add the information for this room into the state so that
|
||||
// it will get added with all of the rest of the joined rooms.
|
||||
state[roomID] = s
|
||||
newlyJoinedRooms[roomID] = true
|
||||
stateFiltered[roomID] = s
|
||||
}
|
||||
|
||||
// We won't add joined rooms into the delta at this point as they
|
||||
|
@ -395,7 +413,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
|
|||
deltas = append(deltas, types.StateDelta{
|
||||
Membership: membership,
|
||||
MembershipPos: ev.StreamPosition,
|
||||
StateEvents: d.StreamEventsToEvents(device, stateStreamEvents),
|
||||
StateEvents: d.StreamEventsToEvents(device, stateFiltered[roomID]),
|
||||
RoomID: roomID,
|
||||
})
|
||||
break
|
||||
|
@ -407,7 +425,7 @@ func (d *DatabaseTransaction) GetStateDeltas(
|
|||
for _, joinedRoomID := range joinedRoomIDs {
|
||||
deltas = append(deltas, types.StateDelta{
|
||||
Membership: gomatrixserverlib.Join,
|
||||
StateEvents: d.StreamEventsToEvents(device, state[joinedRoomID]),
|
||||
StateEvents: d.StreamEventsToEvents(device, stateFiltered[joinedRoomID]),
|
||||
RoomID: joinedRoomID,
|
||||
NewlyJoined: newlyJoinedRooms[joinedRoomID],
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue