mikebronner / laravel-model-caching

Eloquent model-caching made easy.
MIT License
2.23k stars 212 forks source link

Having clauses missing from the generated CacheKey #403

Closed charlie-waddell closed 6 months ago

charlie-waddell commented 3 years ago

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 commented 3 years ago

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

Restingo commented 2 years ago

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

mikebronner commented 1 year ago

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