To make sure we get the latest-consistent result when there are multiple transactions, I use SELECT ... LOCK IN SHARE MODE. I thought this should fix everything
SELECT ... LOCK IN SHARE MODE