2021-01-08 17:59:06 +01:00
|
|
|
package streams
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
|
|
|
"github.com/matrix-org/dendrite/syncapi/types"
|
|
|
|
)
|
|
|
|
|
2022-09-30 13:48:10 +02:00
|
|
|
type DefaultStreamProvider struct {
|
2021-01-08 17:59:06 +01:00
|
|
|
DB storage.Database
|
|
|
|
latest types.StreamPosition
|
|
|
|
latestMutex sync.RWMutex
|
|
|
|
}
|
|
|
|
|
2022-09-30 13:48:10 +02:00
|
|
|
func (p *DefaultStreamProvider) Setup(
|
|
|
|
ctx context.Context, snapshot storage.DatabaseTransaction,
|
|
|
|
) {
|
2021-01-08 17:59:06 +01:00
|
|
|
}
|
|
|
|
|
2022-09-30 13:48:10 +02:00
|
|
|
func (p *DefaultStreamProvider) Advance(
|
2021-01-08 17:59:06 +01:00
|
|
|
latest types.StreamPosition,
|
|
|
|
) {
|
|
|
|
p.latestMutex.Lock()
|
|
|
|
defer p.latestMutex.Unlock()
|
|
|
|
|
|
|
|
if latest > p.latest {
|
|
|
|
p.latest = latest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 13:48:10 +02:00
|
|
|
func (p *DefaultStreamProvider) LatestPosition(
|
2021-01-08 17:59:06 +01:00
|
|
|
ctx context.Context,
|
|
|
|
) types.StreamPosition {
|
|
|
|
p.latestMutex.RLock()
|
|
|
|
defer p.latestMutex.RUnlock()
|
|
|
|
|
|
|
|
return p.latest
|
|
|
|
}
|