Title: Multisite Cron Issues
Last modified: April 6, 2021

---

# Multisite Cron Issues

 *  [michaelcartersa](https://wordpress.org/support/users/michaelcartersa/)
 * (@michaelcartersa)
 * [4 years, 12 months ago](https://wordpress.org/support/topic/multisite-cron-issues/)
 * Hi
 * I’ve had some issues on the site with long mysql query times on the cron tasks.
   Even if you setup the cron to run externally as mentioned in the [documentation](https://deliciousbrains.com/wp-offload-ses/doc/cron-setup/)
   the requests often time out.
 * We are running a fairly big (150+) multisite – but this shouldn’t really be an
   issue. I had a look at the queries and the database tables and I figured out 
   that the indexes need to be changed slightly.
 * **Queries causing issues**
 *     ```
       UPDATE wp_oses_attachments attachments
       LEFT JOIN wp_oses_email_attachments email_attachments ON email_attachments.attachment_id = attachments.id
       SET attachments.gc = ?
       WHERE email_attachments.attachment_id IS NULL
   
       443462 ms (call count 2)
   
       DELETE wp_oses_email_attachments
       FROM wp_oses_email_attachments
       LEFT JOIN wp_oses_emails ON wp_oses_email_attachments.email_id = wp_oses_emails.email_id
       WHERE wp_oses_emails.email_id IS NULL
   
       102463 ms (call count 2)
   
       DELETE wp_oses_emails, wp_oses_clicks FROM wp_oses_emails
       LEFT JOIN wp_oses_clicks ON wp_oses_emails.email_id = wp_oses_clicks.email_id
       WHERE wp_oses_emails.email_created < NOW() - INTERVAL ? DAY
       AND wp_oses_emails.subsite_id = ?
   
       1127 ms (call count 2)
       ```
   
 * **Tables and row counts**
 *     ```
       wp_oses_emails = 15754
       wp_oses_attachments = 4051
       wp_oses_email_attachments = 4677
       ```
   
 * **Changes (based on the queries) I suggest making:**
    - wp_oses_emails: adding a basic index on the subsite_id column (not composite)
    - wp_oses_email_attachments: removing the composite index completely, adding
      two separate indexes for email_id and attachment_id. No need to have a index
      on the filename column.
 * The cleanup cron used to average around 5-10 minutes to run per site, now it 
   runs in .1s per site.
 * Hope this helps someone!
 * Cheers,
    Michael
    -  This topic was modified 4 years, 12 months ago by [michaelcartersa](https://wordpress.org/support/users/michaelcartersa/).
      Reason: formatting

Viewing 1 replies (of 1 total)

 *  Thread Starter [michaelcartersa](https://wordpress.org/support/users/michaelcartersa/)
 * (@michaelcartersa)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/multisite-cron-issues/#post-14515291)
 * Has anyone even looked at this?

Viewing 1 replies (of 1 total)

The topic ‘Multisite Cron Issues’ is closed to new replies.

 * ![](https://ps.w.org/wp-ses/assets/icon-256x256.jpg?rev=2070048)
 * [WP Offload SES Lite](https://wordpress.org/plugins/wp-ses/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-ses/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-ses/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-ses/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-ses/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-ses/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [michaelcartersa](https://wordpress.org/support/users/michaelcartersa/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/multisite-cron-issues/#post-14515291)
 * Status: not resolved