How to avoid flooding DB queries

Ok I need to rethink my logic with this in mind (case closed):

1 Like