The issue
I've been experiencing frequent downtime on my forum lately. After investigating, my hosting provider's support identified the cause: the generation of numerous large MySQL queries with many nested subqueries. For example:
I've tried using Clockwork to debug this, but I haven't been able to identify what's generating such massive queries. Visiting discussions generates much smaller queries, so that's probably not the issue. I suspect the cause might be heavy bot traffic (like Google crawlers) triggering these massive queries when accessing certain parts of the forum.
This as a serious performance issue, as these large queries are putting excessive load on the MySQL server, eventually causing it to crash.
Flarum information
Flarum core: 1.8.9
PHP version: 8.3.7
MySQL version: 11.4.3-MariaDB
Loaded extensions: Core, date, libxml, openssl, pcre, sqlite3, zlib, bz2, calendar, ctype, curl, hash, filter, ftp, gettext, json, iconv, SPL, pcntl, random, readline, Reflection, session, standard, mbstring, shmop, SimpleXML, tokenizer, xml, apcu, bcmath, dba, dom, fileinfo, geoip, gd, gmp, igbinary, imagick, inotify, msgpack, mailparse, mcrypt, memcache, memcached, exif, imap, intl, ldap, mysqlnd, mysqli, PDO, odbc, pgsql, pdo_mysql, pdo_sqlite, PDO_ODBC, pdo_pgsql, Phar, posix, redis, soap, sockets, sodium, snmp, sysvmsg, xmlreader, xmlwriter, xsl, zip, yaml, ionCube Loader, Zend OPcache
+-----------------------------------+---------------------------------------+------------------------------------------+
| Flarum Extensions | | |
+-----------------------------------+---------------------------------------+------------------------------------------+
| ID | Version | Commit |
+-----------------------------------+---------------------------------------+------------------------------------------+
| flarum-flags | v1.8.2 | |
| flarum-tags | v1.8.3 | |
| flarum-approval | v1.8.2 | |
| flarum-lock | v1.8.2 | |
| flarum-gdpr | 1.0.0-beta.3 | |
| flarum-mentions | v1.8.5 | |
| flarum-subscriptions | v1.8.1 | |
| fof-pages | 1.0.8 | |
| v17development-support | v2.8.0 | |
| flarum-suspend | v1.8.4 | |
| fof-follow-tags | 1.2.7 | |
| fof-sitemap | 2.2.1 | |
| fof-byobu | 1.3.8 | |
| acpl-mobile-tab | 1.4.4 | |
| fof-user-directory | 1.3.3 | |
| aberit-communities | dev-master | |
| blomstra-turnstile | 0.1.6 | |
| flarum-markdown | v1.8.1 | |
| sycho-move-posts | v0.1.7 | |
| clarkwinkelmann-author-change | 1.0.3 | |
| fof-masquerade | 2.1.5 | |
| fof-best-answer | 1.6.0 | |
| fof-oauth | 1.6.14 | |
| fof-drafts | 1.2.12 | |
| aberit-gamification | dev-master | |
| fof-nightmode | 1.6.0 | |
| flarumite-simple-discussion-views | 1.2.4 | |
| v17development-seo | v2.0.3 | |
| the-turk-diff | dev-fix-parse-and-render-missing-args | e2a10587855af0b9141d9efb30b4aa4de90e057e |
| ianm-twofactor | 1.1.3 | |
| ianm-html-head | 1.2.4 | |
| ianm-follow-users | 1.4.10 | |
| fof-username-request | 1.2.4 | |
| fof-user-bio | 1.4.2 | |
| fof-upload | 1.6.1 | |
| fof-terms | 1.4.1 | |
| fof-socialprofile | 1.1.6 | |
| fof-polls | 2.2.9 | |
| fof-merge-discussions | 1.4.1 | |
| fof-ignore-users | 1.2.1 | |
| fof-geoip | 1.5.0 | |
| fof-formatting | 1.0.3 | |
| fof-anti-spam | 1.1.2 | |
| flarum-statistics | v1.8.1 | |
| flarum-lang-polish | dev-master | |
| flarum-emoji | v1.8.1 | |
| flarum-bbcode | v1.8.0 | |
| flarum-akismet | v1.8.1 | |
| blomstra-realtime | 0.3.2 | |
| blomstra-cache-assets | 0.5 | |
| askvortsov-rich-text | v2.1.7 | |
| askvortsov-pwa | v3.4.1 | |
| askvortsov-moderator-warnings | v0.6.3 | |
| acpl-lscache | v3.2.1 | |
| aberit-moderation-tools | dev-master | |
| aberit-forum | dev-master | |
| aberit-follow-communities | dev-master | |
| aberit-ads | dev-master | |
+-----------------------------------+---------------------------------------+------------------------------------------+
Queue driver: redis
Session driver: redis (Code override. Configured to file)
Scheduler status: Active
Mail driver: smtp
Debug mode: off