Replace binary search with cumulative size scan for threshold cleanup#3898
Merged
guiyanakuang merged 2 commits intomainfrom Feb 16, 2026
Merged
Replace binary search with cumulative size scan for threshold cleanup#3898guiyanakuang merged 2 commits intomainfrom
guiyanakuang merged 2 commits intomainfrom
Conversation
The old deleteStorageOfApproximateSize used binary search over timestamp space, issuing 30+ DB queries (O(log N) iterations × 1 query each) per cleanup cycle. Replace with a single-pass cumulative size scan that streams oldest non-favorite rows in batches of 500, stopping as soon as the target cleanup size is reached — typically 1-2 queries for moderate datasets.
Use (createTime, id) composite cursor instead of createTime alone to avoid skipping rows with duplicate createTime values at batch boundaries.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getOldestNonFavoriteCreateTimeAndSizeSQL query for batched row streamingfindCleanTimeByCumulativeSize()in PasteDao for cursor-based accumulationDateUtilsimport and@OptIn(ExperimentalTime::class)annotationCloses #3897
Test plan
CleanPasteTaskExecutorTesttests pass./gradlew ktlintFormatpasses./gradlew app:desktopTest— all 209 tests pass