Skip to content
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) #6567

Closed
ruark opened this issue Oct 24, 2024 Discussed in #6566 · 3 comments
Closed
Labels
bug Verified bug by the Nova team fix incoming A fix is in review
Milestone

Comments

@ruark
Copy link

ruark commented Oct 24, 2024

Repo for reproduce: https://github.com/ruark/nova-issue-6564

Discussed in #6566

Originally posted by ruark October 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.

In continuation to issue #6564

This is not related to the database type. I tested with PostgreSQL - the same bug is present there too. Tried with a fresh installation.

To reproduce the problem, add the following code to the register() method of the App\Providers\AppServiceProvider class:

DB::listen(function ($query) {
    Log::debug($query->sql, $query->bindings);
});

Then open the index page of any resource, for example https://site/nova/resources/users.

Next, look at the log file, where you will see something like this:
[2024-10-24 03:52:32] local.DEBUG: select * from "users" where "users"."id" is null limit 1

Full log: laravel.log

Repo for reproduce: https://github.com/ruark/nova-issue-6564

If you also can't reproduce the problem and close this issue - I promise, I will not write about this problem here anymore. After that, for myself, I will correct this behavior locally of a patch. In this case, unfortunately, other Nova customers will sooner or later face this problem. Judging by the number of closed issues, where other people have already reported to you several times about problems with requests when opening the resource index page.

@crynobone crynobone added the pending Issues that are pending triage label Dec 4, 2024
@crynobone crynobone added this to the 5.1.x milestone Dec 19, 2024
@crynobone
Copy link
Member

This seems to been fixed alongside other changes to Laravel Nova 5. laravel/nova@4b318ce5

@crynobone crynobone modified the milestones: 5.1.x, 5.0.x Dec 31, 2024
@crynobone crynobone added bug Verified bug by the Nova team fix incoming A fix is in review and removed pending Issues that are pending triage labels Dec 31, 2024
@ruark
Copy link
Author

ruark commented Dec 31, 2024

This seems to been fixed alongside other changes to Laravel Nova 5. laravel/nova@4b318ce5

So support for Nova 4 is over?

@crynobone
Copy link
Member

No plan release for Laravel Nova 4 at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified bug by the Nova team fix incoming A fix is in review
Projects
None yet
Development

No branches or pull requests

2 participants