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