diff --git a/handlers/services.go b/handlers/services.go index 6e97420d..94ea5b81 100644 --- a/handlers/services.go +++ b/handlers/services.go @@ -547,15 +547,10 @@ func apiAllServicesStatusHandler(w http.ResponseWriter, r *http.Request) { var srvs []services.ServiceWithDowntime m := make(map[int64]downtimes.Downtime) if t == "" { - dtime := downtimes.FindDowntime2() - log.Println("FindDowntime2 results") - log.Println(dtime) - fmt.Println(dtime) - for i := 0; i < len(dtime); i+=1 { - downtimeVar := dtime[i] - serviceVar, _ := services.Find(downtimeVar.ServiceId) - if serviceVar.Online ==false { - m[downtimeVar.ServiceId] = downtimeVar + for _, v := range services.AllInOrder() { + if v.Online == false { + downtime:= downtimes.FindDowntime3(v.Id) + m[v.Id] = downtime } } } else { diff --git a/types/downtimes/database.go b/types/downtimes/database.go index b14fe553..55d5a97d 100644 --- a/types/downtimes/database.go +++ b/types/downtimes/database.go @@ -67,10 +67,9 @@ func FindDowntime(timeVar time.Time) []Downtime { return downtime } -func FindDowntime2() []Downtime { - var downtime []Downtime - db.Raw("select d1.* from downtimes d1 left join downtimes d2 on d1.service = d2.service and d2.start > d1.start where d2.service is NULL;").Scan(&downtime) - //db.Select("downtimes.*").Joins("left join downtimes as d2 on d2.service = downtimes.service AND downtimes.start < d2.start").Where("d2.end = ?",nil).Find(&downtime) +func FindDowntime3(service int64) Downtime { + var downtime Downtime + db.Raw("select * from downtimes where service = ? order by start desc limit 1;",service).Scan(&downtime) return downtime }