mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-25 21:21:35 +00:00
6348486a13
This should transactional snapshot isolation for `/sync` etc requests. For now we don't use repeatable read due to some odd test failures with invites.
41 lines
729 B
Go
41 lines
729 B
Go
package streams
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
|
"github.com/matrix-org/dendrite/syncapi/types"
|
|
)
|
|
|
|
type DefaultStreamProvider struct {
|
|
DB storage.Database
|
|
latest types.StreamPosition
|
|
latestMutex sync.RWMutex
|
|
}
|
|
|
|
func (p *DefaultStreamProvider) Setup(
|
|
ctx context.Context, snapshot storage.DatabaseTransaction,
|
|
) {
|
|
}
|
|
|
|
func (p *DefaultStreamProvider) Advance(
|
|
latest types.StreamPosition,
|
|
) {
|
|
p.latestMutex.Lock()
|
|
defer p.latestMutex.Unlock()
|
|
|
|
if latest > p.latest {
|
|
p.latest = latest
|
|
}
|
|
}
|
|
|
|
func (p *DefaultStreamProvider) LatestPosition(
|
|
ctx context.Context,
|
|
) types.StreamPosition {
|
|
p.latestMutex.RLock()
|
|
defer p.latestMutex.RUnlock()
|
|
|
|
return p.latest
|
|
}
|