I've been wondering for a while if there are any predefined queries in Flarum to optimise the database. For example, for WordPress we have queries like this one, which deletes some orphaned data:
DELETE wp_postmeta FROM wp_postmeta
LEFT JOIN wp_posts ON (wp_postmeta.post_id = wp_posts.ID)
WHERE (wp_posts.ID IS NULL)
However, for Flarum I can't find anything that can help locate unnecessary data or that can be optimised, so to date the only maintenance I'm doing on my sites is scheduling a generic optimisation via phpMyAdmin.
Maintaining a clean and organised database, free of unnecessary data can really speed up site performance, I think it's a healthy thing to do. I thought I'd open this thread if anyone has or wants to share some useful queries, something like :
DELETE FROM posts
WHERE discussion_id IS NOT NULL
AND discussion_id NOT IN (SELECT id FROM discussions);