Slow Flask-SQLAlchemy query using association tables
Saw your post on indiehackers. I don't know this orm, but generally speaking, I see you have two options.

Decide to preload/precache the data when your app starts and refresh it occasionally, if you insist on having all records available. 

But some good advice I've read is : never do in real time what you can do in advance. So... Why not even build some "top posts" table and seed that?