You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel多租户应用InnoDB表达万条记录后无法新增条目问题

问题描述
  • 部署环境:Ubuntu服务器 + InnoDB MySQL数据库 + Laravel多租户应用(包含至少10个功能类似的租户)
  • 异常现象:当某租户的通用租户表记录数超过9980条时,尝试向该表新增条目会导致整个应用崩溃,SQL服务CPU占用率飙升至190%,所有租户无法使用应用;其他记录数未达到该阈值的租户可正常新增条目
  • 补充信息:通过Workbench查看该表,预估总大小仅6.5MiB;删除部分记录后应用恢复正常,但记录数再次达到9980时问题复现
相关Update函数代码
public function update(Request $request, $id)
{
    $form = GeneralSpecimen::find($id);
    $patient = Patient::where('id', $form->patient_id)->first();
    $patientName = $patient->first_name . " " . $patient->last_name;
    $patientNum = $patient->patient_number;
    $patientPhoneNumber = $patient->phone;
    $pathologyNumber = $form->pathology_number;
    $formName = "GeneralSpecimen Form";
    $sms = new SmsHelper();

    // Get current Hostname Tenant Facility
    $hostname  = app(\Hyn\Tenancy\Environment::class)->hostname();
    $tenantFacilityName = $hostname->tenant_facility_name;

    $form->update( $request->except( 'auth_signature' ) );

    $billPat = Bill::where('id', $form->bill_id)->first();

    $new_arr = [];
    if(!is_null($billPat)){
          //* storing the column with clinical module items inside a variable [pathology_number]
        $pathology_number =  $billPat->clinical_module_items;


        //*creating an empty array to store the updated array containing the new pathology number


        //*looping through the clinical_module array to extract the pathology number using the key
        foreach( $billPat->clinical_module_items as $key =>$value){

        //*reassigning the pathology number with the new value
         $value['pathology_number'] =request()->pathology_number;

        //* Pushing the updated value array inside the new empty array created
        array_push($new_arr, $value);
        }
    }
    //*Finally updating the clinical_module column with the new array created
    Bill::where('id',$form->bill_id)->update(['clinical_module_items'=>$new_arr]);

    if( $request->submission_ready != 1 )  $form->update([ 'case_status' => 'pending']) ;

    if( !is_null( $this->getSignature() )  && $request->submission_ready == 1 )
    {   # health facility name for address
        $healthFacility = DB::table('health_facility_profiles')->first();
        $healthFacility == null ? $address = $tenantFacilityName : $address = $healthFacility->name_of_facility;
        $form->update([ 'auth_signature' =>  $this->updateSignature( auth()->guard('api')->user()->id ) ]) ;

        # update patient with the new generated password
        //$patient->update(['password' => password_hash($this->password, PASSWORD_DEFAULT)]);

        if( !is_null($patient->email) )
        {  # send email
            Mail::to($patient->email)->send(new PatientEmail($patientName, $patient->test_password, $patientNum, $hostname->tenant_facility_name));
        }
        if($sms->isEnabled == 1 && $sms->bundle > 1)
        {   # send sms
           $sms->sendSpecimenReadySms($patientPhoneNumber, $patientName, $pathologyNumber, $formName, $address, $patient->test_password, $patientNum);
        }

        if(!is_null($patientPhoneNumber))
        {  #send WhatsAppMessage
           $sms->sendSpecimenReadyWhatsAppMessage($patientPhoneNumber, $patientName, $pathologyNumber, $formName, $address, $patient->test_password, $patientNum);
        }

        $form->update([ 'case_status' =>  'ready' ]);
        $message = "Specimen updated successfully. An SMS has been sent to Patient";
        return response(compact('message'), 200);

    }
    else if( is_null( $this->getSignature() ))
    {
        $message = "Kindly Upload Your Digital Signature to Finalize this Report" ;
        return response(compact('message'), 200);
    }

    $message = "Specimen form updated" ;
    return response(compact("message"), 200);
}

内容的提问来源于stack exchange,提问作者Divine Teyi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 05:08:07