frontend: speed-up the models.Batch related routes
We don't have to do a SeqScan through all the Builds when we calculate
the Batch tree — we can just go through those builds that really
reference some batch.
Also, constructing the Batch tree needs one SQL query for each node, and
each of those queries took about ~200ms before — there was a missing
index.
Merges: #2091
Fixes: #2090