Giter Club home page Giter Club logo

Comments (7)

mpociot avatar mpociot commented on May 3, 2024 1

I pushed some commits in order to take the last stack trace frame into account.
Unfortunately, there's currently no way to fix this:

       $user = Auth()->user();
       $user->load('banks.accounts.balances', 'accounts.balances');

from laravel-query-detector.

janpio avatar janpio commented on May 3, 2024

I could reproduce it on another page, where it is a bit clearer why the data is loaded:

$user->banks->accounts->balances
$user->accounts->balances

These are two ways to get the same data. As the page is looping over ->accounts of both $user->banks and $user for two different parts of the interface, this seems to trigger the alert:

Found the following N+1 queries in this request:

Model: App\Account => Relation: App\Balance - You should add "with('AppBalance')" to eager-load this relation.

Is this expected?

from laravel-query-detector.

mpociot avatar mpociot commented on May 3, 2024

What do you mean by routes? Then I can try to see if this can be detected.
The problem is that I can only listen for sql queries and then need to backtrack from there.
Hmm maybe I should just use the latest stack trace location to determine if the calls are actually duplicates. That might be a good idea :)

from laravel-query-detector.

janpio avatar janpio commented on May 3, 2024

See my second post for an example of "routes": There are two ways to get from a to b via relationships in this app's relationship model. This results in the same query being fired twice, but I couldn't find a way to avoid that until now with Eloquent.

from laravel-query-detector.

janpio avatar janpio commented on May 3, 2024

In this app I can trigger the faulty behavior by just doing this:

       $user = Auth()->user();
       $user->load('banks.accounts.balances', 'accounts.balances');

from laravel-query-detector.

mpociot avatar mpociot commented on May 3, 2024

In this case, this package will be unable to tell the difference.
I will add the backtrack source location as another unique parameter to check. This will at least minimize this a lot, I guess.

And well, in theory you still do resolve the same relation twice.

from laravel-query-detector.

janpio avatar janpio commented on May 3, 2024

I know, but: Is there a way around that?

from laravel-query-detector.

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.