mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-01-01 01:38:26 +00:00
use exclusive writer, and MarkPeeksAsOld more efficiently
This commit is contained in:
parent
5d7f688fa7
commit
6424117852
1 changed files with 20 additions and 6 deletions
|
@ -1005,7 +1005,7 @@ func (d *Database) getStateDeltas(
|
||||||
}
|
}
|
||||||
|
|
||||||
// find out which rooms this user is peeking, if any.
|
// find out which rooms this user is peeking, if any.
|
||||||
// We do this before joins so joins overwrite peeks
|
// We do this before joins so any peeks get overwritten
|
||||||
peeks, err := d.Peeks.SelectPeeks(ctx, userID, device.ID)
|
peeks, err := d.Peeks.SelectPeeks(ctx, userID, device.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -1013,6 +1013,7 @@ func (d *Database) getStateDeltas(
|
||||||
|
|
||||||
// add peek blocks
|
// add peek blocks
|
||||||
peeking := make(map[string]bool)
|
peeking := make(map[string]bool)
|
||||||
|
newPeeks := false
|
||||||
for _, peek := range peeks {
|
for _, peek := range peeks {
|
||||||
peeking[peek.RoomID] = true
|
peeking[peek.RoomID] = true
|
||||||
if peek.New {
|
if peek.New {
|
||||||
|
@ -1023,6 +1024,7 @@ func (d *Database) getStateDeltas(
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
state[peek.RoomID] = s
|
state[peek.RoomID] = s
|
||||||
|
newPeeks = true
|
||||||
}
|
}
|
||||||
|
|
||||||
deltas = append(deltas, stateDelta{
|
deltas = append(deltas, stateDelta{
|
||||||
|
@ -1032,8 +1034,10 @@ func (d *Database) getStateDeltas(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(peeks) > 0 {
|
if newPeeks {
|
||||||
err := d.Peeks.MarkPeeksAsOld(ctx, txn, userID, device.ID)
|
err = d.Writer.Do(d.DB, txn, func(txn *sql.Tx) error {
|
||||||
|
return d.Peeks.MarkPeeksAsOld(ctx, txn, userID, device.ID)
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -1051,7 +1055,11 @@ func (d *Database) getStateDeltas(
|
||||||
if membership == gomatrixserverlib.Join {
|
if membership == gomatrixserverlib.Join {
|
||||||
if peeking[roomID] {
|
if peeking[roomID] {
|
||||||
// we automatically cancel our peeks when we join a room
|
// we automatically cancel our peeks when we join a room
|
||||||
_, err = d.Peeks.DeletePeeks(ctx, txn, roomID, userID)
|
err = d.Writer.Do(d.DB, txn, func(txn *sql.Tx) error {
|
||||||
|
// XXX: is it correct that we're discarding the streamid here?
|
||||||
|
_, err = d.Peeks.DeletePeeks(ctx, txn, roomID, userID)
|
||||||
|
return err
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -1130,7 +1138,11 @@ func (d *Database) getStateDeltasForFullStateSync(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add full states for all peeking rooms
|
// Add full states for all peeking rooms
|
||||||
|
newPeeks := false
|
||||||
for _, peek := range peeks {
|
for _, peek := range peeks {
|
||||||
|
if peek.New {
|
||||||
|
newPeeks = true
|
||||||
|
}
|
||||||
s, stateErr := d.currentStateStreamEventsForRoom(ctx, txn, peek.RoomID, stateFilter)
|
s, stateErr := d.currentStateStreamEventsForRoom(ctx, txn, peek.RoomID, stateFilter)
|
||||||
if stateErr != nil {
|
if stateErr != nil {
|
||||||
return nil, nil, stateErr
|
return nil, nil, stateErr
|
||||||
|
@ -1142,8 +1154,10 @@ func (d *Database) getStateDeltasForFullStateSync(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(peeks) > 0 {
|
if newPeeks {
|
||||||
err := d.Peeks.MarkPeeksAsOld(ctx, txn, userID, device.ID)
|
err = d.Writer.Do(d.DB, txn, func(txn *sql.Tx) error {
|
||||||
|
return d.Peeks.MarkPeeksAsOld(ctx, txn, userID, device.ID)
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue