- Issue created by @scuba_fly
- 🇮🇳India abhishek@kumar
Database-Level Locking
// In WebformSubmissionForm.php or similar handler
public function validateForm(array &$form, FormStateInterface $form_state) {
$webform = $this->getWebform();// Get exclusive lock for this webform
$lock_id = 'webform_submission_limit:' . $webform->id();
if (!$this->lock->acquire($lock_id)) {
$form_state->setErrorByName('', $this->t('Submission processing, please try again.'));
return;
}try {
// Check submission limit with lock held
if ($webform->hasSubmissionLimit() && $webform->isSubmissionLimitExceeded()) {
$form_state->setErrorByName('', $webform->getSubmissionLimitExceededMessage());
}
}
finally {
$this->lock->release($lock_id);
}
} - 🇳🇱Netherlands scuba_fly Netherlands, Vinkeveen
Adding a patch (WIP) but have to stop for today.
I'll create a proper MR later and still have to do some testing.
- 🇳🇱Netherlands scuba_fly Netherlands, Vinkeveen
I'm still experiencing more submissions then the set limit in a simulation where 25 users submit the webform around the same time.
At this point I'm thinking a custom handler that would write to the database in the validate might be better.
So only users that would have a record in the database would be validated.
The database would look like:
[webform_id] [submittion_count]Then in the validate it would lock the database table, get the webform_id submission count. write the webform_id, and add added submission.
Then after the user has submit the webform and drupal handled the submission. release the lock.