DivineTeyi's avatar

Laravel Application cant create new database entries after a maximum of 10000 entries

I have a Laravel application that writes and reads from a mysql database setup on innodb sql serve in ubuntu. The application is a multi-tenant application and has at least 10 tenancies that performs similar functionalities. However, I realized that one tenancy has over 9980 entries in one of the common tenancy tables. When that particular tenancy tries to add another entry to the table, the whole app crashes but other tenancies can add to their copy copy of that table without any issues because they do not have that number of entries. When this happens the sql service runs at around 190% of processing power and the application can not be used by anyone, including those in other tenancies.

This is the create function

	public function store(Request $request, PathologyUtilityController $pathUtils)
{
    $patient = Patient::where('id', $request->patient_id)->first();
    $patientName = $patient->first_name . " " . $patient->last_name;
    $patientNum = $patient->patient_number;
    $patientPhoneNumber = $patient->phone;
    $pathologyNumber = $request->pathology_number;
    $formName = "General Specimen Form";
    $caseId = $pathUtils->generateCaseId('GS-', 'general_specimens');
    $sms = new SmsHelper();
    $form =  GeneralSpecimen::create( $request->except( 'auth_signature' ) );
    $form->update( ['case_id' => $caseId] );
    // Get current Hostname Tenant Facility
    $hostname  = app(\Hyn\Tenancy\Environment::class)->hostname();
    $tenantFacilityName = $hostname->tenant_facility_name;

    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->test_password)){
            $patient->update(['test_password' => random_int(100000, 999999)]);
        }

        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 = "New Specimen Ready. 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);
    }
    else
    {
        $message = "New Specimen Created" ;
        return response(compact('message'), 200);
    }



}

other tenancies that have not reached similar number of entries use the same functions to create new entries without any problem

I inspected the table information in workbench and realized that the total size estimate in is only 6.5 MiB. On deleting some entries, I could add more forms to the app without any problems but once I reach the initial number, the app breaks. This application has been in use for almost six years and I haven't had any issue with it until now. There are other tables with up to 40000 rows but still work without any problems. Please what am I missing here?

0 likes
0 replies

Please or to participate in this conversation.