[autotest] use parent_id to reduce number of db queries in suite.wait

This CL reduces the number of queries required when waiting for a
suite's job results, by replacing (when suite_job_id is known) a loop
over afe.get_jobs(id=job.id, finished=True) for all remaining jobs in a
suite with a single call to
afe.get_jobs(parent_job_id=parent_job_id, finished=True)

I have not yet done a performance benchmark with this change, nor
examined whether the underlying SQL queries could be significantly
optimized with an intelligently chosen new database index.

CQ-DEPEND=CL:I4b407fd0cc1a769ad0d4829bdffed87213e2da04
BUG=chromium:276471
TEST=Used run_suite locally, verified that suite waiting on its child
jobs and that results were reported correctly. Added a unit test, which
passes.

Change-Id: I47dbc5f1a3348bdd5297ffbd2e26b82dc9d705f6
Reviewed-on: https://gerrit.chromium.org/gerrit/66443
Reviewed-by: Aviv Keshet <akeshet@chromium.org>
Tested-by: Aviv Keshet <akeshet@chromium.org>
Commit-Queue: Aviv Keshet <akeshet@chromium.org>
4 files changed