- there is a CAPTCHA data table with 2 million pieces of data. CAPTCHA fields need to be unique
- you need to insert a large amount of data into this table, about tens of thousands of pieces of data at a time
- how to optimize the execution time of each time
current practice:
-
Mr.
- makes an array containing the unique CAPTCHA.
- check the verification code table according to the array, and find the existing regenerations
- 5000 insert in batches at a time
private function generateUniqueValidationCodes(int $number)
{
//
$codeArr = $this->generateUniqueCodes($number);
//
$result = ValidationCode::query()->whereIn("validation_code", $codeArr)->get();
//
if ($result->isNotEmpty()) {
$this->generateUniqueValidationCodes($number);
} else {
return $codeArr;
}
}