Comments (20)
Thanks for reporting this @shez1983 ! I'll take a look as soon as I get back to the office on Tuesday. In the mean time, can you provide the SQL representation of both queries?
from laravel-model-caching.
i'll make sure I update this post before tuesday.. Thanks :)
from laravel-model-caching.
If you are able to, please include the stack trace as well. I do have about 30 minutes to look at it right now, if you are able to update the code :)
from laravel-model-caching.
Related or same as #66
from laravel-model-caching.
@shez1983 Are inRandomOrder()
and live()
query scopes? Can you paste them here as well? Thanks! :)
from laravel-model-caching.
I am sorry for the delay... :(
"select * from `product_variants` where exists (select * from `products` where `product_variants`.`product_id` = `products`.`id` and `category_id` = ? and `status_id` = ? and `show_on_mobile` = ?) and `is_listed` = ? and (`stock` is null or `stock` > ?) and `product_variants`.`deleted_at` is null order by RAND()"
Here is the live Scope
{
return $q->whereIsListed(1)->where(function($q)
{
return $q->whereNull('stock')->orWhere('stock', '>', 0);
});
}
inRandomOrder is an ELOQUENT/Builder function btw..
I am not sure how to include a stack trace because theres no error..
from laravel-model-caching.
@shez1983 thanks for the update. In your eloquent query you aren't specifying get()
? Was that just a typo, or are you using a different command?
from laravel-model-caching.
yes. as i said i can see the actual products.. if i didnt specify get() i wouldnt have come to the conclusion of my OP.. :)
from laravel-model-caching.
Hi @shez1983, I am unable to reproduce this problem in version 0.2.37. Can you test again? I have added a test that checks the caching for the whereHas()
method. Please let me know how it goes! :)
See test here: https://github.com/GeneaLabs/laravel-model-caching/blob/master/tests/Unit/CachedModelTest.php#L77
from laravel-model-caching.
@shez1983 closing this for now, please let me know if you continue to have this problem.
from laravel-model-caching.
oops sorry - too busy with work will let you know sometime (by next week)
btw that link https://github.com/GeneaLabs/laravel-model-caching/blob/master/tests/Unit/CachedModelTest.php#L77 doesnt seem to be working :s
@mikebronner
from laravel-model-caching.
from laravel-model-caching.
Thanks for that - seeing your test, it seems you have not understood my problem...
that test is not recreating what i said in my op..
in that test i expected you to cache both
->with('author')
->whereHas('author', function ($query) {
$query->whereId(1);
})
->get();
and
->with('author')
->whereHas('author', function ($query) {
$query->whereId(2);
})
->get();
and then make sure the results are not the same..
notice the Ids.. are different
from laravel-model-caching.
Thanks for clarifying, that indeed was not clear in your initial post. I will try to recreate the problem as you just described.
from laravel-model-caching.
@shez1983 I added the following test: d003028
Does this follow your use-case? I was unable to replicate the issue.
from laravel-model-caching.
-
$this->assertNotEmpty($books1->diffKeys($books2));
surely this should assertEMPTY if there can only be one author for a book? and you are not caching the results...
you are supposed to be looking at cached results (Unless i am missing something) not comparing eloquent/query results...
from laravel-model-caching.
Your original post was saying that running two different queries actually returns the same information. Do I understand that correctly?
This test does use caching, and it verifies that the results from each cached query are different. That is to say, that the results provided in $books2
are not the same as those in $books1
. Since whereHas
queries are cached, as verified in the test above this one, it is not necessary to verify that. We only need to make sure that the second query is not pulling the cache from the first query.
Have you actually been able to recreate this issue with the latest version of the package?
from laravel-model-caching.
yes thats correct. in your previous test (link you provided:
https://github.com/GeneaLabs/laravel-model-caching/blob/master/tests/Integration/CachedModelTest.php#L77
you were doing
$cachedResults = $this
->cache()
->tags($tags)
->get($key)['value'];
$this->assertEquals(1, $books->first()->author->id);
$this->assertEquals(1, $cachedResults->first()->author->id);
so i was expecting something similar in your latest test you did... d003028
anyway i will re-test (i actually tested it again few days after posting to make sure i didnt make an error) & let you know
from laravel-model-caching.
Thanks, I look forward to seeing how it works for you! :)
from laravel-model-caching.
HI @shez1983, closing this for now. If there are still issues, please go ahead and re-open. Thanks :)
from laravel-model-caching.
Related Issues (20)
- Only flush cache when delete() returns a count
- Clear cache in a record of the model. HOT 2
- Saving not working with eloquent strict mode HOT 2
- What is cacheCooldownSecounds definition? HOT 1
- Add support for Laravel 10 HOT 2
- Object of class Illuminate\\Database\\Query\\Expression could not be converted to string HOT 6
- Since 0.12.4 I get error "GeneaLabs\LaravelModelCaching\CacheKey::processEnum(): Argument #1 ($value) must be of type BackedEnum|UnitEnum|string, null given, called in ...\vendor\genealabs\laravel-model-caching\src\CacheKey.php on line 409" HOT 23
- Cannot access "parent" when current class scope has no parent HOT 1
- Laravel v10.3.0 breaks LaravelModelCaching HOT 2
- checkCooldownAndFlushAfterPersisting(): Argument #2 ($relationship) must be of type string, array given, called in /var/www/html/vendor/genealabs/laravel-model-caching/src/Traits/ModelCaching.php on line 83 HOT 8
- Is table join supported? HOT 7
- The attribute [column3] either does not exist or was not retrieved for model HOT 1
- Stale cached value returned where(...)->first() HOT 4
- Fix for GeneaLabs\LaravelModelCaching\CacheKey::processEnum(): Argument #1 ($value) must be of type BackedEnum|UnitEnum|string, null given
- processEnum(): Argument #1 ($value) must be of type BackedEnum|UnitEnum|Illuminate\Database\Query\Expression|string, null given HOT 2
- Conflict with Spatie Schemaless
- Laravel 11 upgrade blocked by laravel-pivot-events dependency HOT 1
- Missing import in CachedBuilder?
- Fix failing tests HOT 1
- Uuid fromBytes throwing a error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-model-caching.