0

Fix buggy saving of lastDisconnectTime now used for #1111

This commit is contained in:
Gabe Kangas 2021-06-20 11:30:29 -07:00
parent b19fa76cd0
commit 89dfcfb047
3 changed files with 13 additions and 6 deletions

View File

@ -327,14 +327,14 @@ func SetPeakOverallViewerCount(count int) error {
} }
// GetLastDisconnectTime will return the time the last stream ended. // GetLastDisconnectTime will return the time the last stream ended.
func GetLastDisconnectTime() (time.Time, error) { func GetLastDisconnectTime() (utils.NullTime, error) {
var disconnectTime time.Time var disconnectTime utils.NullTime
configEntry, err := _datastore.Get(lastDisconnectTimeKey) configEntry, err := _datastore.Get(lastDisconnectTimeKey)
if err != nil { if err != nil {
return disconnectTime, err return disconnectTime, err
} }
if err := configEntry.getObject(disconnectTime); err != nil { if err := configEntry.getObject(&disconnectTime); err != nil {
return disconnectTime, err return disconnectTime, err
} }
@ -343,7 +343,8 @@ func GetLastDisconnectTime() (time.Time, error) {
// SetLastDisconnectTime will set the time the last stream ended. // SetLastDisconnectTime will set the time the last stream ended.
func SetLastDisconnectTime(disconnectTime time.Time) error { func SetLastDisconnectTime(disconnectTime time.Time) error {
var configEntry = ConfigEntry{Key: lastDisconnectTimeKey, Value: disconnectTime} savedDisconnectTime := utils.NullTime{Time: disconnectTime, Valid: true}
var configEntry = ConfigEntry{Key: lastDisconnectTimeKey, Value: savedDisconnectTime}
return _datastore.Save(configEntry) return _datastore.Save(configEntry)
} }

View File

@ -146,12 +146,18 @@ func saveStats() error {
func getSavedStats() models.Stats { func getSavedStats() models.Stats {
savedLastDisconnectTime, savedLastDisconnectTimeErr := data.GetLastDisconnectTime() savedLastDisconnectTime, savedLastDisconnectTimeErr := data.GetLastDisconnectTime()
var lastDisconnectTime utils.NullTime
if savedLastDisconnectTimeErr == nil {
lastDisconnectTime = savedLastDisconnectTime
}
result := models.Stats{ result := models.Stats{
ChatClients: make(map[string]models.Client), ChatClients: make(map[string]models.Client),
Viewers: make(map[string]time.Time), Viewers: make(map[string]time.Time),
SessionMaxViewerCount: data.GetPeakSessionViewerCount(), SessionMaxViewerCount: data.GetPeakSessionViewerCount(),
OverallMaxViewerCount: data.GetPeakOverallViewerCount(), OverallMaxViewerCount: data.GetPeakOverallViewerCount(),
LastDisconnectTime: utils.NullTime{Time: savedLastDisconnectTime, Valid: savedLastDisconnectTimeErr == nil}, LastDisconnectTime: lastDisconnectTime,
} }
// If the stats were saved > 5min ago then ignore the // If the stats were saved > 5min ago then ignore the

View File

@ -30,7 +30,6 @@ var _currentBroadcast *models.CurrentBroadcast
// setStreamAsConnected sets the stream as connected. // setStreamAsConnected sets the stream as connected.
func setStreamAsConnected() { func setStreamAsConnected() {
_stats.StreamConnected = true _stats.StreamConnected = true
_stats.LastConnectTime = utils.NullTime{Time: time.Now(), Valid: true} _stats.LastConnectTime = utils.NullTime{Time: time.Now(), Valid: true}
_stats.LastDisconnectTime = utils.NullTime{Time: time.Now(), Valid: false} _stats.LastDisconnectTime = utils.NullTime{Time: time.Now(), Valid: false}
@ -161,6 +160,7 @@ func SetStreamAsDisconnected() {
StartOfflineCleanupTimer() StartOfflineCleanupTimer()
stopOnlineCleanupTimer() stopOnlineCleanupTimer()
saveStats()
go webhooks.SendStreamStatusEvent(models.StreamStopped) go webhooks.SendStreamStatusEvent(models.StreamStopped)
} }