fix(delete_by_expiry): add missing bind parameter and handle string-to-number conversion#98
Merged
genusistimelord merged 3 commits intoAscendingCreations:mainfrom Oct 14, 2025
Conversation
genusistimelord
approved these changes
Oct 14, 2025
Member
genusistimelord
left a comment
There was a problem hiding this comment.
thank you for catching and fixing this issue.
Member
|
if that Optimization is indeed an optimizations I don't see why you would not just include it? |
Contributor
Author
|
I didn't want to mix the fix with the optimization in this PR, and I was not sure if there was a good reason to separate the query into SELECT + DELETE. I've now included the change in the last commit. |
genusistimelord
approved these changes
Oct 14, 2025
Member
genusistimelord
left a comment
There was a problem hiding this comment.
approved the change. thank you
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.
Problem
The
delete_by_expiryfunction had two bugs that prevented it from cleaning up expired sessions:$expiresbut never bound it, causing the queryto return empty results
sessionexpiresis stored as a string (e.g.,'1760389854'), the comparisonsessionexpires < $expiresfails because SurrealDB compares string-to-number incorrectlySolution
.bind(("expires", now))to the SELECT querysessionexpireswithtype::number()in both SELECT and DELETE queries to ensure proper numeric comparisonTesting
Tested in my project with thousands of expired sessions that were not being cleaned up. After the fix, all expired sessions are now properly deleted.
Optional Further Optimization
This fix maintains the current two-query approach (SELECT + DELETE). However, SurrealDB supports
RETURN BEFOREin DELETE statements, which would allow combining both queries into one:Let me know if you'd like me to include this optimization in the PR as well.