Reduce SQL query count in /scheduler/mydevicetypehealthhistory

Results:
* before: 32 queries in ~20ms
* after :  7 queries in ~10ms

Signed-off-by: Rémi Duraffort <remi.duraffort@linaro.org>
18 jobs for sql-efficiency in 16 minutes and 34 seconds (queued for 10 seconds)
Status Name Job ID Coverage
  Test
passed dispatcher-debian-10 #140794
amd64

00:02:32

passed dispatcher-debian-11 #140796
amd64

00:02:31

passed server-debian-10 #140795
amd64

00:02:59

passed server-debian-11 #140797
amd64

00:05:07

 
  Analyze
passed bandit-sast #140798
amd64-dind

00:01:03

passed black #140801
amd64

00:00:47

passed code_quality #140802
amd64

00:00:24

passed codespell #140807
amd64

00:00:23

passed coverage #140803
amd64

00:07:08

61.02%
passed dockerfiles #140804
amd64

00:00:16

passed eslint-sast #140799
amd64-dind

00:00:26

passed pylint #140806
amd64

00:02:41

passed schemas #140805
amd64

00:00:36

passed semgrep-sast #140800
amd64-dind

00:01:19

 
  Build
passed debian/10 #140809
amd64

00:01:18

passed doc #140808
amd64

00:00:39

passed docker-amd64-dispatcher #140810
amd64-dind

00:03:53

passed docker-amd64-server #140811
amd64-dind

00:04:12