Advanced WP Query hogs the SQL server

There are several options:

  • Use some Lucene-based search index and cache your queries there. Power it with lots of RAM so nothing hits your DB after the first query. Use something like…
    • Elasticsearch
    • Solr
    • Sphinx
    • Do not attempt to run Lucene plain … you will find yourself in hell. Nobody does that for a good reason.
  • Rewrite your Query and use a raw query instead of \WP_Query.
  • Split your query into different queries. Cache the result in a key/value storage (db-server).
    • Use Memcached (meh)…
    • or Redis (better, as you can cluster it and it configures better with load balanced installations.)
  • The easiest way out: Write an update script that loops over your 300 objects/estates. 300 is not much. Convert it to a taxonomy. Ease your life in the long run.

Recommendations:

  • Log slow queries.
  • Add monitoring to your stack.
  • Alert yourself when things go off. Fix it, before your client knows. Inform them about what you fixed. Have happy clients for a long time. Find out that CLV is underrated.