nri: Database query optimization

4 jobs for noc-797 in 17 seconds (queued for 2 seconds)