Query exceeding server limit, but in the local is ok, Orange

Asked

Viewed 23 times

-1

I wonder if you have how to optimize this query, not have to change server for now.

$enterprisesIds = Survey::select('survey_enterprise.enterprise_id')
            ->join('survey_enterprise', 'survey_enterprise.survey_id', '=','surveys.id')
            ->where('survey_enterprise.survey_id', $this->surveyId)
            ->pluck('survey_enterprise.enterprise_id')->map(fn ($item) => (string) $item)->toArray();

            return Enterprise::select('categories.name as categoryname','enterprises.cnpj', 'enterprises.name as razaosocial','enterprises.id' )
            ->join('categories', 'categories.id', '=','enterprises.category_id')
            ->where('categories.syndicate_id', Auth::guard('syndicate')->user()->syndicate_id)
            ->whereNotIn('enterprises.id', $enterprisesIds)
            ->when($this->selectedCategory, function ($query) {
                $query->where('category_id', $this->selectedCategory);
            })
            ->search(trim($this->search));
  • Could you format the code for better display? Here we use the markdown.

  • You can try debugging the query, see how in the documentation, to better understand the problem. Having it in hand, perform directly in the database and measure performance.

  • I’ve done it, gave 467ms..

  • I take first the IDS and play at wherein - not to take the companies that are linked in Urvey, I wanted to do it straight, without having to put these IDS in Where, I think that’s what is taking.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.