highest ID rather than the highest timestamp. Otherwise, if a build from revision N finishes after a build from revision N + 1, then the build from revision N will end up in the channel. Thus, the channel contents will be out of sync.
This is still not quite correct: if a revision reverts to an older build, the channel will still end up out of sync, because Hydra won't schedule the build again (after all, it has already done it). A better fix would be to add a separate timestamp denoting when the build was last "current" (i.e. corresponding to the "head revision" of its job).
EJFVQ33SDMTAQ7HIRGIX5NPPXKZJ3KCB7LFSPLQ5KRMDMK6XLE2QC
makeSource('JobStatus' . $name, "select * from (select project, jobset, job, system, max(timestamp) timestamp from Builds where finished = 1 $constraint group by project, jobset, job, system) natural join Builds");
makeSource('LatestSucceeded' . $name, "select * from (select project, jobset, job, system, max(timestamp) timestamp from Builds natural join BuildResultInfo where finished = 1 and buildStatus = 0 $constraint group by project, jobset, job, system) natural join Builds");
makeSource('JobStatus' . $name, "select * from (select project, jobset, job, system, max(id) id from Builds where finished = 1 $constraint group by project, jobset, job, system) natural join Builds");
makeSource('LatestSucceeded' . $name, "select * from (select project, jobset, job, system, max(id) id from Builds natural join BuildResultInfo where finished = 1 and buildStatus = 0 $constraint group by project, jobset, job, system) natural join Builds");