Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having clauses missing from the generated CacheKey #403

Merged
merged 5 commits into from
Dec 23, 2023

Conversation

charlie-waddell
Copy link
Contributor

@charlie-waddell charlie-waddell commented Jun 24, 2021

The issue:

When a query has having clauses, the changes are not detected because these appear to be missed from the generation of the cache key. Example:

// Assume there are 100 orders, the count will be 100
Order::query()
    ->selectRaw('updated_at as aliased_updated_at')
    ->count();

// Assume there are only 50 with an updated_at value greater than the given date/time,
// the count wil be pulled from the cached result of the above query, giving us 100 instead of 50
Order::query()
    ->selectRaw('updated_at as aliased_updated_at')
    ->having('aliased_updated_at', '>' ,'2021-01-01 00:00:00')
    ->count()

@mikebronner
Copy link
Owner

@charlie-waddell Thanks so much for taking the time to write up a PR. I will try to get this merged soon.

@mikebronner mikebronner self-assigned this Jun 24, 2021
Copy link
Owner

@mikebronner mikebronner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this! Could you write some tests to cover the code you added? Thanks!

Charlie Waddell added 2 commits May 27, 2022 16:14
@Restingo
Copy link

Restingo commented Jul 4, 2022

@charlie-waddell did you find some time to add tests? Thank you.

@mikebronner
Copy link
Owner

If anyone would like to pick this up and add tests, that would be great. I'm happy to merge once those are in.

Signed-off-by: Mike Bronner <mike@genealabs.com>
@mikebronner mikebronner merged commit 19bcdf2 into mikebronner:master Dec 23, 2023
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants