sort-by with db/-count breaks queries on empty database before transact #269
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.
UPDATE: THIS PR DOES NOT FIX THE ISSUE
What this PR does
Reverts the sort (short term fix). Feel free to merge it orclose it when you work out the caching issue. I tried to delve into the cache stuff but that is going to take me a fair bit longer to get to grips with.What the issue was
So I’ve encountered this weird issue where if I run a query on an empty database before running a transaction it makes subsequent queries return nil for that attribute.
This should work, but doesn’t.
This does work.
So it’s this commit that introduces the issue:
720a7d7
I've also tried reverting this commit on the latest master and it fixes the issue.
So this seems to be caused by this line:
https://github.com/juji-io/datalevin/blob/master/src/datalevin/query.clj#L1468
sort-by (fn [[_ attr _]] (db/-count db [nil attr nil]))
My guess is db/-count is stateful and is now getting called in the reduce and the sort, where as before it was just being called in the reduce. So caching most likely.