changed stuff

pull/1097/head
Rhythm 2022-02-25 16:12:24 +05:30
parent 48decee356
commit 8b7e17ed89
2 changed files with 7 additions and 13 deletions

View File

@ -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 {

View File

@ -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
}