Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mgalante324's avatar

Public variables slowing down events

I have 3 public variables in my component that hold queries. I load them up once and then use them throughout the component in different functions. Everything works fine on my localhost and is plenty fast, however, once I uploaded it to the live version on our server, there was a long wait every time I click on a wire:click button. The initial load is still perfectly fine, but after that it can take anywhere from 13-30 seconds to call the function after clicking the button, even if the only code in the function is dd("hello");

I've never run into an issue like this before, the server is always faster than my localhost, and this issue does not appear on any of my other livewire components throughout the site. The only reason I bring up the 3 public query variables is because I noticed if I make them not-public then everything works fine again. I'm just confused as to why this problem would only appear on the server and not my localhost.

0 likes
2 replies
martinbean's avatar

@mgalante324 Local environments are not production environments. If these public properties are “queries” or the result of queries, then I imagine your production environment will have many, many more database rows than your local environment with dummy seed data. So if you’re stuffing lots of data into memory then yes, that’s just going to get slower and slower the more data you save and pass around.

So, share code and it may help others point out where things could be improved.

mgalante324's avatar

Thanks for your reply. I am working with a copy of the live database locally, so the data should be the same. As for the code, here are the 3 queries that I mentioned that are being run on the first load:

            $this->sales = DB::table('contacts')
            ->leftJoin('appointments', 'contacts.id', 'appointments.contact_id')
            ->leftJoin('apps', 'contacts.id', 'apps.contact_id')
            ->leftJoin('bars', 'contacts.id', 'bars.contact_id')
            ->leftJoin('results', 'contacts.id', 'results.contact_id')
            ->leftJoin('key_indicators', 'contacts.id', 'key_indicators.contact_id')
            ->where('contacts.company_id', auth()->user()->company_id)
            ->where(function ($query) {
                $query->where('appointments.date', '>=', $this->startDate)
                        ->orWhere('apps.date', '>=', $this->startDate)
                        ->orWhere('bars.date', '>=', $this->startDate);})
            ->where(function ($query) {
                $query->where('appointments.date', '<=', $this->endDate)
                    ->orWhere('apps.date', '<=', $this->endDate)
                    ->orWhere('bars.date', '<=', $this->endDate);})
            ->where(function($query) {
                $query->where('results.results', 'Sold: Net')
                ->orWhere('results.results', 'Sold: Pending')
                ->orWhere('results.results', 'Sold Gross: Holding Pattern')
                ->orWhere('results.results', 'Sold')
                ->orWhere('results.results', 'Sold: Rejected for Finance')
                ->orWhere('results.results', 'Sold: Cancelled');
            })->select('contacts.id as id', 'contacts.primary_first as first', 'contacts.primary_last as last', 'contacts.lead_source_detail as source', 'appointments.date as date', 'appointments.rep as rep', 'appointments.rep2 as rep2',
            'results.gross_sale_amount as gross_sale_amount', 'results.net_sale_amount as net_sale_amount', 'results.results as result', 'key_indicators.exp_manu as exp_manu', 'key_indicators.vol_manu as vol_manu', 
            'key_indicators.manu_payments_complete as manu_payments_complete', 'key_indicators.dont_attribute_manu as dont_attribute_manu',
            'key_indicators.exp_install as exp_install', 'key_indicators.vol_install as vol_install', 'key_indicators.install_payments_complete as install_payments_complete',  'key_indicators.dont_attribute_install as dont_attribute_install',
            'key_indicators.rep_commission as commission1', 'key_indicators.rep2_commission as commission2', 'key_indicators.rep3_commission as commission3', 'key_indicators.rep4_commission as commission4')
            ->orderBy('appointments.date')
            ->get();

            // Get the payments made
            $this->payments = DB::table('p_l_payments')->where('company_id', auth()->user()->company_id)
            ->whereBetween('date', [$this->startDate, $this->endDate])
            ->orderBy('date')
            ->get();

            // Get the leads purchased
            $this->purchasedLeads = InternetLead::where('company_id', auth()->user()->company_id)
            ->whereBetween('date', [$this->startDate, $this->endDate])
            ->orderBy('date')
            ->get();

And here is an example of how I am using them in my functions.

    public function getGrossSales()
    {
        $this->showData['grossSales'] = $this->sales->filter(function (array $value, int $key) {
            return $value['result'] == 'Sold: Net' || 
                   $value['result'] == 'Sold: Pending' ||
                   $value['result'] == 'Sold Gross: Holding Pattern' ||
                   $value['result'] == 'Sold' ||
                   $value['result'] == 'Sold: Rejected for Finance' ||
                   $value['result'] == 'Sold: Cancelled';
        });
    } 

As mentioned previously, even if I have a function that does not use one of these public variables, it will still take a really long time to load after clicking the button to call the function.

Please or to participate in this conversation.