Event replay and cleanup

This commit is contained in:
Ava Apples Affine 2025-01-08 00:47:49 +00:00 committed by piper pentagram
parent 2560410820
commit 97bf66c191
8 changed files with 447 additions and 39 deletions

View file

@ -263,6 +263,11 @@ func NewDocumentBuffer(
* If cache is full oldest document is written to backing writer.
*/
func (b *DocBuf) Push(doc string) error {
if b.cacheSize == 0 {
b.writeToBackingStore(doc)
return nil
}
if len(b.cache) >= b.cacheSize {
if err := b.demote(); err != nil {
return err
@ -280,6 +285,14 @@ func (b *DocBuf) Push(doc string) error {
* out of the backing ReaderWriter.
*/
func (b *DocBuf) Pop() (string, error) {
if b.cacheSize == 0 {
d, e := b.readDocumentsFromDisk(1, true, false)
if len(d) > 0 {
return d[0], e
}
return "", e
}
if len(b.cache) < 1 {
if err := b.promote(true); err != nil {
return "", err