Coder Social home page Coder Social logo

Comments (20)

mikebronner avatar mikebronner commented on June 21, 2024

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.

shez1983 avatar shez1983 commented on June 21, 2024

i'll make sure I update this post before tuesday.. Thanks :)

from laravel-model-caching.

mikebronner avatar mikebronner commented on June 21, 2024

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.

mikebronner avatar mikebronner commented on June 21, 2024

Related or same as #66

from laravel-model-caching.

mikebronner avatar mikebronner commented on June 21, 2024

@shez1983 Are inRandomOrder() and live() query scopes? Can you paste them here as well? Thanks! :)

from laravel-model-caching.

shez1983 avatar shez1983 commented on June 21, 2024

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.

mikebronner avatar mikebronner commented on June 21, 2024

@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.

shez1983 avatar shez1983 commented on June 21, 2024

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.

mikebronner avatar mikebronner commented on June 21, 2024

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.

mikebronner avatar mikebronner commented on June 21, 2024

@shez1983 closing this for now, please let me know if you continue to have this problem.

from laravel-model-caching.

shez1983 avatar shez1983 commented on June 21, 2024

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.

mikebronner avatar mikebronner commented on June 21, 2024

Try this:
https://github.com/GeneaLabs/laravel-model-caching/blob/master/tests/Integration/CachedModelTest.php#L77

from laravel-model-caching.

shez1983 avatar shez1983 commented on June 21, 2024

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.

mikebronner avatar mikebronner commented on June 21, 2024

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.

mikebronner avatar mikebronner commented on June 21, 2024

@shez1983 I added the following test: d003028

Does this follow your use-case? I was unable to replicate the issue.

from laravel-model-caching.

shez1983 avatar shez1983 commented on June 21, 2024
  •    $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.

mikebronner avatar mikebronner commented on June 21, 2024

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.

shez1983 avatar shez1983 commented on June 21, 2024

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.

mikebronner avatar mikebronner commented on June 21, 2024

Thanks, I look forward to seeing how it works for you! :)

from laravel-model-caching.

mikebronner avatar mikebronner commented on June 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.