Is there a maximum limit of association of promotional codes to events?

We have an application that generates massive one-use codes applied to an event. We have to generate 15,000 promo codes with a 100% discount. We have put the ticket limit at 20,000.

We are generating 2000 codes in 2000, but when we pass the 8,000 discount codes associated with an event, we are prevented from editing the event.
When we give it to edit or create an event, it does not open and it gives us a 504 timeout error.

If you delete the codes inserted in wp_esp_promotion, wp_esp_promotion_object, wp_esp_price, the editing and creation of events works perfectly.

Is there a maximum limit of association of promotional codes to events or can they be limitations of our hosting server?

We have another open incident with this problem, but we have redirected it here once we have seen the causes of the error.

In WP-Debug we get the following error:
[07-Nov-2018 19:09:23 UTC] PHP Warning: mysqli_query(): MySQL server has gone away in /home/salonesgqb/www/wp-includes/wp-db.php on line 1924
[07-Nov-2018 19:09:23 UTC] PHP Warning: mysqli_query(): Error reading result set’s header in /home/salonesgqb/www/wp-includes/wp-db.php on line 1924

Version: 4.9.8
Language: es_ES
Permalink structure: /%postname%/
Is this site using HTTPS?: Yes
Can anyone register on this site?: No
Default comment status: closed
Is this a multisite?: No
User Count: 8
Communication with WordPress.org: WordPress.org is reachable
Create loopback requests: The loopback request to your site failed, this may prevent WP_Cron from working, along with theme and plugin editors.<br>Error encountered: (0) cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received

Is there a maximum limit of association of promotional codes to events or can they be limitations of our hosting server?

We don’t have limits on the number of promotions, with a ‘MySQL server has gone away’ error your likely hitting a limitation of your hosting, but that may also mean we need to alter something with our queries.

We’ll need to so do some digging into this, may I ask, how are you creating the promotion codes currently?

Thank you for the code, in future I’d recommend pasting large sections of go to either a Gist, or PasteBin and then adding the URL here, the forum can add formatting to snippets.

Yep, that field is set to 1 automatically by default. Shall we set the field to 0?

Yes, set that field to 0.

Promotion price objects are not ‘default prices’ and thats likely what is causing your problem as default prices are all pulled into the the event editor. It was never expected that a user would have 8,000+ default prices on an event (a default price would usually be asigned to a default ticket, meaning an event with 8,000 default tickets).

—

Side note, is there any reason your not using our models to create these objects?

Had you have used those to add the prices the default field would have automatically been set to 0. I’m going to create a ticket to investigate why that field defaults to 1 but I would still recommend switching the above to use the model system as it handles a lot of what you are doing automatically.

With regards to the models, I’d highly recommend looking into using them, the handle a lot of the background work for you so once you know how to use them its much easier to work with EE than rolling your own.