As I see it, there's a few options, each with its own tradeoffs.
Run the expensive query/calculation when you write relevant data, synchronously, and store it in a way that's optimized for fast reads (ie. in a cache somewhere, or just a JSON blob in the database).
PROS:
- optimized for fast reads, data is kept up to date if you make sure to compute it in every write operation that might affect the outcome.