First hack at trending algorithm.
t = A - B; where A is the time the entry was posted, and B is 2022 0000Z
x = the number of upvotes - the number of downvotes
y = 1 when x > 0, 0 when x = 0, -1 when x < 0
z = x if x >= 1, or 1
rank = log(z) + (yt)/45000
Just call the column trendingRank and have it recalculated for every20th upvote. Then the query just orders by this. Since the newer posts automatically have higher scores you don’t have to recalculate older posts. You only recalculate when new votes are received and only for that specific posts. We may find a way to make newer upvotes count more than older upvotes later.