From d28c4b96f3a024c7e8e733a80cba5d48cda544e6 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Mon, 28 Jun 2021 13:59:23 -0700 Subject: [PATCH] Fix invalid nil time being returned --- core/data/config.go | 2 +- core/stats.go | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/core/data/config.go b/core/data/config.go index 7feb29cfd..6215b8158 100644 --- a/core/data/config.go +++ b/core/data/config.go @@ -328,7 +328,7 @@ func SetPeakOverallViewerCount(count int) error { // GetLastDisconnectTime will return the time the last stream ended. func GetLastDisconnectTime() (utils.NullTime, error) { - var disconnectTime utils.NullTime + var disconnectTime = utils.NullTime{time.Now(), false} configEntry, err := _datastore.Get(lastDisconnectTimeKey) if err != nil { return disconnectTime, err diff --git a/core/stats.go b/core/stats.go index 33e04951c..121942f76 100644 --- a/core/stats.go +++ b/core/stats.go @@ -11,7 +11,6 @@ import ( "github.com/owncast/owncast/core/data" "github.com/owncast/owncast/geoip" "github.com/owncast/owncast/models" - "github.com/owncast/owncast/utils" ) var l = &sync.RWMutex{} @@ -145,19 +144,14 @@ func saveStats() error { } func getSavedStats() models.Stats { - savedLastDisconnectTime, savedLastDisconnectTimeErr := data.GetLastDisconnectTime() - - var lastDisconnectTime utils.NullTime - if savedLastDisconnectTimeErr == nil && savedLastDisconnectTime.Valid { - lastDisconnectTime = savedLastDisconnectTime - } + savedLastDisconnectTime, _ := data.GetLastDisconnectTime() result := models.Stats{ ChatClients: make(map[string]models.Client), Viewers: make(map[string]time.Time), SessionMaxViewerCount: data.GetPeakSessionViewerCount(), OverallMaxViewerCount: data.GetPeakOverallViewerCount(), - LastDisconnectTime: lastDisconnectTime, + LastDisconnectTime: savedLastDisconnectTime, } // If the stats were saved > 5min ago then ignore the