Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Excessive database query when getting resource index (select ... from ... where id is null) #6564

Closed
ruark opened this issue Oct 23, 2024 · 7 comments
Labels
needs more info More information is required

Comments

@ruark
Copy link

ruark commented Oct 23, 2024

  • Laravel Version: 11.27.2
  • Nova Version: 4.35.3
  • PHP Version: 8.2.24
  • Database Driver & Version: oci8 (yajra/laravel-oci8 11.6.2)

Description:

When we open the resource index, the system makes a strange query to the database like this:
select * from (select * from "TABLE" where "TABLE"."ID" is null) where rownum = 1

In this case, "id" is the primary key. This behavior is implemented in the method findModel($resourceId = null) in the trait \vendor\laravel\nova\src\Http\Requests\InteractsWithResources.php

Such a query is executed every time when accessing the index of any resource that does not carry any logic. However, given a large table in the database, it greatly affects performance.

@crynobone
Copy link
Member

Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

@crynobone crynobone added the needs more info More information is required label Oct 24, 2024
@ruark
Copy link
Author

ruark commented Oct 24, 2024

public function findModel($resourceId = null)
    {
        return rescue(function () use ($resourceId) {
            return $this->findModelOrFail($resourceId);
        }, $this->model(), false);
    }

What happens if $resourceId = null?
In this case, the database query that I wrote about above will be generated.
As far as I understand, in this case an instance of the model should be returned, but this does not happen.

@crynobone
Copy link
Member

What happens if $resourceId = null?

In what scenario does it become null in resource index view? We need reproducing repository to replicate the issue.

@ruark
Copy link
Author

ruark commented Oct 24, 2024

As far as I understand, this happens when the available actions are received.

vendor/laravel/nova/src/Http/Controllers/ActionController.php

 public function index(NovaRequest $request)
    {
        $resourceId = with($request->input('resources'), function ($resourceIds) {
            return is_array($resourceIds) && count($resourceIds) === 1 ? $resourceIds[0] : null;
        });

        $resource = $request->newResourceWith(
            $request->findModel($resourceId) ?? $request->model()
        );

@ruark
Copy link
Author

ruark commented Oct 24, 2024

I saw this when I logged all the queries being executed to the database.

@ruark
Copy link
Author

ruark commented Oct 24, 2024

In what scenario does it become null in resource index view?

And in principle, it doesn't matter in what scenario this can happen, if the findModel function can take an argument $resourceId = null

@crynobone
Copy link
Member

Unable to replicate this on MySQL or SQLite. Seem to be specific issue to Oracle which we don't have official support.

@laravel laravel locked and limited conversation to collaborators Oct 24, 2024
@crynobone crynobone converted this issue into discussion #6566 Oct 24, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
needs more info More information is required
Projects
None yet
Development

No branches or pull requests

2 participants