Skip to content

Commit c19dc02

Browse files
committed
optimize
1 parent 4db3dc3 commit c19dc02

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

pkg/store/store_adapter.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ const (
2323
// When this limit is reached, Append will block until items are pruned.
2424
maxPendingCacheSize = 10_000
2525

26-
// pruneThreshold is the number of appends before we trigger a prune of already-persisted items.
27-
pruneThreshold = 100
28-
2926
// pruneRetryInterval is how long to wait between prune attempts when cache is full.
3027
pruneRetryInterval = 50 * time.Millisecond
3128
)
@@ -303,9 +300,6 @@ type StoreAdapter[H EntityWithDAHint[H]] struct {
303300
// Bounded by maxPendingCacheSize with backpressure when full.
304301
pending *pendingCache[H]
305302

306-
// appendCount tracks appends to trigger periodic pruning
307-
appendCount atomic.Uint64
308-
309303
// onDeleteFn is called when items are deleted (for rollback scenarios)
310304
onDeleteFn func(context.Context, uint64) error
311305
}
@@ -642,11 +636,6 @@ func (a *StoreAdapter[H]) Append(ctx context.Context, items ...H) error {
642636
}
643637
}
644638

645-
// Periodically prune items that have been persisted to the store
646-
if a.appendCount.Add(1)%pruneThreshold == 0 {
647-
a.prunePersisted(ctx)
648-
}
649-
650639
return nil
651640
}
652641

@@ -677,8 +666,13 @@ func (a *StoreAdapter[H]) waitForSpace(ctx context.Context) error {
677666

678667
// prunePersisted removes items that have already been persisted to the underlying store.
679668
func (a *StoreAdapter[H]) prunePersisted(ctx context.Context) {
669+
storeHeight, err := a.getter.Height(ctx)
670+
if err != nil || storeHeight == 0 {
671+
return
672+
}
673+
// Items at or below store height are definitely persisted
680674
a.pending.pruneIf(func(height uint64) bool {
681-
return a.getter.HasAt(ctx, height)
675+
return height <= storeHeight
682676
})
683677
}
684678

0 commit comments

Comments
 (0)