question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Tabs feature launches dozens of duplicate queries

See original GitHub issue

As you can see in the attached pic, as soon as I activate Tabs, previous 6 queries jumps to 30, most of them duplicated. Debugbar traces the queries to view::crud::inc.show_tabbed_fields:41 located in show_tabbed_fields.blade.php, that reads @include('crud::inc.show_fields', ['fields' => $crud->getTabFields($tab)])

I wasn’t able to trace it any further, but I confirmed the issue dissapears if I remove the tabs. Confirmed also in Gitter with @OwenMelbz and @automat64 so it doesn’t seem to be something with my setup.

image

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
kram-dyollcommented, Mar 9, 2017

Okay @MarcosBL here we go

First we’ll need to create the class we will use to override the base class in the vendor directory. I’ll be storing the files in the app/Src/Backpack directory.

Create the following class and call it CrudPanel. Notice this extends \Backpack\CRUD\CrudPanel and we are just overriding the getEntity method (this is found in the read trait in the CrudPanel class we are extending)

namespace App\Src\Backpack;

class CrudPanel extends \Backpack\CRUD\CrudPanel
{
    /**
     * The method we want to override
     */
    public function getEntry($id)
    {
        if (!$this->entry) {
            $this->entry = $this->model->findOrFail($id);
            $this->entry = $this->entry->withFakes();
        }
        return $this->entry;
    }
}

We also need to create a new CrudController as this is where the CrudPanel is used. Create the following class. Notice we are extending the \Backpack\CRUD\app\Http\Controllers\CrudController class. We are only overriding the constructor as we need to ensure we are using our newly created CrudPanel. As we are still in the same namespace App\Src\Backpack the CrudPanel will be our created one 😃

namespace App\Src\Backpack;

class CrudController extends \Backpack\CRUD\app\Http\Controllers\CrudController
{
    public function __construct()
    {
        if (! $this->crud) {
            $this->crud = app()->make(CrudPanel::class);
            $this->middleware(function ($request, $next) {
                $this->request = $request;
                $this->crud->request = $request;
                $this->setup();

                return $next($request);
            });
        }
    }
}

The only thing left to do is use our newly created class App\Src\Backpack\CrudController instead of the standard \Backpack\CRUD\app\Http\Controllers\CrudController in all of our Crud Controllers that have the issue. Just swap out the class you are extending from \Backpack\CRUD\app\Http\Controllers\CrudController to App\Src\Backpack\CrudController.

I hope this helps.

If you’re still stuck just ask.

1reaction
kram-dyollcommented, Mar 9, 2017

No problem @MarcosBL, glad it helped.

Please be aware this is not a fix, just a workaround. The getEntity method is still getting called multiple times. This workaround just ensures the query is called only once!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reformulating Queries for Duplicate Bug Report Detection
Abstract—When bugs are reported, one important task is to check if they are new or if they were reported before. Many.
Read more >
Tab History - Duplicate Entries - Redgate forums
For duplicate tabs, I'm finding that one instance opens the tab as expected and the duplicate instance displays an error Document not found....
Read more >
142855 - Duplicate history entries in BACK menu - Monorail
Issue 142855: Duplicate history entries in BACK menu · 1. close all tabs, and close browser · 2. open browser with default blank...
Read more >
Dashboard Tabs and Unwanted Query Duplicates
I just realized that when I was cloning my dashboards and tabs I was leaving "Clone Query" selected- that is probably causing the...
Read more >
Firefox repeatedly opens empty tabs or windows after you ...
Firefox may repeatedly open new, empty tabs or windows after you click on a link, forcing you to close Firefox. The same untitled...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found