mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-26 08:13:09 -06:00
Only initiate wakeups if the stream advanced
This commit is contained in:
parent
e8695f1ee6
commit
d5ec531ddb
|
|
@ -95,8 +95,9 @@ func (s *OutputClientDataConsumer) onMessage(msg *sarama.ConsumerMessage) error
|
||||||
}).Panicf("could not save account data")
|
}).Panicf("could not save account data")
|
||||||
}
|
}
|
||||||
|
|
||||||
s.stream.Advance(streamPos)
|
if s.stream.Advance(streamPos) {
|
||||||
s.notifier.OnNewAccountData(string(msg.Key), types.StreamingToken{AccountDataPosition: streamPos})
|
s.notifier.OnNewAccountData(string(msg.Key), types.StreamingToken{AccountDataPosition: streamPos})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,8 +90,9 @@ func (s *OutputReceiptEventConsumer) onMessage(msg *sarama.ConsumerMessage) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.stream.Advance(streamPos)
|
if s.stream.Advance(streamPos) {
|
||||||
s.notifier.OnNewReceipt(output.RoomID, types.StreamingToken{ReceiptPosition: streamPos})
|
s.notifier.OnNewReceipt(output.RoomID, types.StreamingToken{ReceiptPosition: streamPos})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,12 +105,13 @@ func (s *OutputSendToDeviceEventConsumer) onMessage(msg *sarama.ConsumerMessage)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.stream.Advance(streamPos)
|
if s.stream.Advance(streamPos) {
|
||||||
s.notifier.OnNewSendToDevice(
|
s.notifier.OnNewSendToDevice(
|
||||||
output.UserID,
|
output.UserID,
|
||||||
[]string{output.DeviceID},
|
[]string{output.DeviceID},
|
||||||
types.StreamingToken{SendToDevicePosition: streamPos},
|
types.StreamingToken{SendToDevicePosition: streamPos},
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,8 +101,9 @@ func (s *OutputTypingEventConsumer) onMessage(msg *sarama.ConsumerMessage) error
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.stream.Advance(typingPos)
|
if s.stream.Advance(typingPos) {
|
||||||
s.notifier.OnNewTyping(output.Event.RoomID, types.StreamingToken{TypingPosition: typingPos})
|
s.notifier.OnNewTyping(output.Event.RoomID, types.StreamingToken{TypingPosition: typingPos})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,10 +122,11 @@ func (s *OutputKeyChangeEventConsumer) onMessage(msg *sarama.ConsumerMessage) er
|
||||||
Partition: msg.Partition,
|
Partition: msg.Partition,
|
||||||
}
|
}
|
||||||
|
|
||||||
s.stream.Advance(posUpdate)
|
if s.stream.Advance(posUpdate) {
|
||||||
for userID := range queryRes.UserIDsToCount {
|
for userID := range queryRes.UserIDsToCount {
|
||||||
s.notifier.OnNewKeyChange(types.StreamingToken{DeviceListPosition: posUpdate}, userID, output.UserID)
|
s.notifier.OnNewKeyChange(types.StreamingToken{DeviceListPosition: posUpdate}, userID, output.UserID)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -186,8 +186,9 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.pduStream.Advance(pduPos)
|
if s.pduStream.Advance(pduPos) {
|
||||||
s.notifier.OnNewEvent(ev, ev.RoomID(), nil, types.StreamingToken{PDUPosition: pduPos})
|
s.notifier.OnNewEvent(ev, ev.RoomID(), nil, types.StreamingToken{PDUPosition: pduPos})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -226,8 +227,9 @@ func (s *OutputRoomEventConsumer) onOldRoomEvent(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.pduStream.Advance(pduPos)
|
if s.pduStream.Advance(pduPos) {
|
||||||
s.notifier.OnNewEvent(ev, ev.RoomID(), nil, types.StreamingToken{PDUPosition: pduPos})
|
s.notifier.OnNewEvent(ev, ev.RoomID(), nil, types.StreamingToken{PDUPosition: pduPos})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -283,8 +285,9 @@ func (s *OutputRoomEventConsumer) onNewInviteEvent(
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s.inviteStream.Advance(pduPos)
|
if s.inviteStream.Advance(pduPos) {
|
||||||
s.notifier.OnNewInvite(types.StreamingToken{InvitePosition: pduPos}, *msg.Event.StateKey())
|
s.notifier.OnNewInvite(types.StreamingToken{InvitePosition: pduPos}, *msg.Event.StateKey())
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -303,8 +306,9 @@ func (s *OutputRoomEventConsumer) onRetireInviteEvent(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify any active sync requests that the invite has been retired.
|
// Notify any active sync requests that the invite has been retired.
|
||||||
s.inviteStream.Advance(pduPos)
|
if s.inviteStream.Advance(pduPos) {
|
||||||
s.notifier.OnNewInvite(types.StreamingToken{InvitePosition: pduPos}, msg.TargetUserID)
|
s.notifier.OnNewInvite(types.StreamingToken{InvitePosition: pduPos}, msg.TargetUserID)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -324,8 +328,9 @@ func (s *OutputRoomEventConsumer) onNewPeek(
|
||||||
// tell the notifier about the new peek so it knows to wake up new devices
|
// tell the notifier about the new peek so it knows to wake up new devices
|
||||||
// TODO: This only works because the peeks table is reusing the same
|
// TODO: This only works because the peeks table is reusing the same
|
||||||
// index as PDUs, but we should fix this
|
// index as PDUs, but we should fix this
|
||||||
s.pduStream.Advance(sp)
|
if s.pduStream.Advance(sp) {
|
||||||
s.notifier.OnNewPeek(msg.RoomID, msg.UserID, msg.DeviceID, types.StreamingToken{PDUPosition: sp})
|
s.notifier.OnNewPeek(msg.RoomID, msg.UserID, msg.DeviceID, types.StreamingToken{PDUPosition: sp})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -345,8 +350,9 @@ func (s *OutputRoomEventConsumer) onRetirePeek(
|
||||||
// tell the notifier about the new peek so it knows to wake up new devices
|
// tell the notifier about the new peek so it knows to wake up new devices
|
||||||
// TODO: This only works because the peeks table is reusing the same
|
// TODO: This only works because the peeks table is reusing the same
|
||||||
// index as PDUs, but we should fix this
|
// index as PDUs, but we should fix this
|
||||||
s.pduStream.Advance(sp)
|
if s.pduStream.Advance(sp) {
|
||||||
s.notifier.OnRetirePeek(msg.RoomID, msg.UserID, msg.DeviceID, types.StreamingToken{PDUPosition: sp})
|
s.notifier.OnRetirePeek(msg.RoomID, msg.UserID, msg.DeviceID, types.StreamingToken{PDUPosition: sp})
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,16 @@ func (p *PartitionedStreamProvider) Setup() {
|
||||||
|
|
||||||
func (p *PartitionedStreamProvider) Advance(
|
func (p *PartitionedStreamProvider) Advance(
|
||||||
latest types.LogPosition,
|
latest types.LogPosition,
|
||||||
) {
|
) bool {
|
||||||
p.latestMutex.Lock()
|
p.latestMutex.Lock()
|
||||||
defer p.latestMutex.Unlock()
|
defer p.latestMutex.Unlock()
|
||||||
|
|
||||||
if latest.IsAfter(&p.latest) {
|
if latest.IsAfter(&p.latest) {
|
||||||
p.latest = latest
|
p.latest = latest
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PartitionedStreamProvider) LatestPosition(
|
func (p *PartitionedStreamProvider) LatestPosition(
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,16 @@ func (p *StreamProvider) Setup() {
|
||||||
|
|
||||||
func (p *StreamProvider) Advance(
|
func (p *StreamProvider) Advance(
|
||||||
latest types.StreamPosition,
|
latest types.StreamPosition,
|
||||||
) {
|
) bool {
|
||||||
p.latestMutex.Lock()
|
p.latestMutex.Lock()
|
||||||
defer p.latestMutex.Unlock()
|
defer p.latestMutex.Unlock()
|
||||||
|
|
||||||
if latest > p.latest {
|
if latest > p.latest {
|
||||||
p.latest = latest
|
p.latest = latest
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *StreamProvider) LatestPosition(
|
func (p *StreamProvider) LatestPosition(
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ type StreamProvider interface {
|
||||||
Setup()
|
Setup()
|
||||||
|
|
||||||
// Advance will update the latest position of the stream based on
|
// Advance will update the latest position of the stream based on
|
||||||
// an update and will wake callers waiting on StreamNotifyAfter.
|
// an update. It returns true if the position advanced or false otherwise.
|
||||||
Advance(latest StreamPosition)
|
Advance(latest StreamPosition) bool
|
||||||
|
|
||||||
// CompleteSync will update the response to include all updates as needed
|
// CompleteSync will update the response to include all updates as needed
|
||||||
// for a complete sync. It will always return immediately.
|
// for a complete sync. It will always return immediately.
|
||||||
|
|
@ -46,7 +46,7 @@ type StreamProvider interface {
|
||||||
|
|
||||||
type PartitionedStreamProvider interface {
|
type PartitionedStreamProvider interface {
|
||||||
Setup()
|
Setup()
|
||||||
Advance(latest LogPosition)
|
Advance(latest LogPosition) bool
|
||||||
CompleteSync(ctx context.Context, req *SyncRequest) LogPosition
|
CompleteSync(ctx context.Context, req *SyncRequest) LogPosition
|
||||||
IncrementalSync(ctx context.Context, req *SyncRequest, from, to LogPosition) LogPosition
|
IncrementalSync(ctx context.Context, req *SyncRequest, from, to LogPosition) LogPosition
|
||||||
LatestPosition(ctx context.Context) LogPosition
|
LatestPosition(ctx context.Context) LogPosition
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue