mirror of
https://github.com/owncast/owncast.git
synced 2024-11-25 06:12:23 +03:00
Fix buggy saving of lastDisconnectTime now used for #1111
This commit is contained in:
parent
b19fa76cd0
commit
89dfcfb047
3 changed files with 13 additions and 6 deletions
|
@ -327,14 +327,14 @@ func SetPeakOverallViewerCount(count int) error {
|
|||
}
|
||||
|
||||
// GetLastDisconnectTime will return the time the last stream ended.
|
||||
func GetLastDisconnectTime() (time.Time, error) {
|
||||
var disconnectTime time.Time
|
||||
func GetLastDisconnectTime() (utils.NullTime, error) {
|
||||
var disconnectTime utils.NullTime
|
||||
configEntry, err := _datastore.Get(lastDisconnectTimeKey)
|
||||
if err != nil {
|
||||
return disconnectTime, err
|
||||
}
|
||||
|
||||
if err := configEntry.getObject(disconnectTime); err != nil {
|
||||
if err := configEntry.getObject(&disconnectTime); err != nil {
|
||||
return disconnectTime, err
|
||||
}
|
||||
|
||||
|
@ -343,7 +343,8 @@ func GetLastDisconnectTime() (time.Time, error) {
|
|||
|
||||
// SetLastDisconnectTime will set the time the last stream ended.
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -146,12 +146,18 @@ func saveStats() error {
|
|||
|
||||
func getSavedStats() models.Stats {
|
||||
savedLastDisconnectTime, savedLastDisconnectTimeErr := data.GetLastDisconnectTime()
|
||||
|
||||
var lastDisconnectTime utils.NullTime
|
||||
if savedLastDisconnectTimeErr == nil {
|
||||
lastDisconnectTime = savedLastDisconnectTime
|
||||
}
|
||||
|
||||
result := models.Stats{
|
||||
ChatClients: make(map[string]models.Client),
|
||||
Viewers: make(map[string]time.Time),
|
||||
SessionMaxViewerCount: data.GetPeakSessionViewerCount(),
|
||||
OverallMaxViewerCount: data.GetPeakOverallViewerCount(),
|
||||
LastDisconnectTime: utils.NullTime{Time: savedLastDisconnectTime, Valid: savedLastDisconnectTimeErr == nil},
|
||||
LastDisconnectTime: lastDisconnectTime,
|
||||
}
|
||||
|
||||
// If the stats were saved > 5min ago then ignore the
|
||||
|
|
|
@ -30,7 +30,6 @@ var _currentBroadcast *models.CurrentBroadcast
|
|||
|
||||
// setStreamAsConnected sets the stream as connected.
|
||||
func setStreamAsConnected() {
|
||||
|
||||
_stats.StreamConnected = true
|
||||
_stats.LastConnectTime = utils.NullTime{Time: time.Now(), Valid: true}
|
||||
_stats.LastDisconnectTime = utils.NullTime{Time: time.Now(), Valid: false}
|
||||
|
@ -161,6 +160,7 @@ func SetStreamAsDisconnected() {
|
|||
|
||||
StartOfflineCleanupTimer()
|
||||
stopOnlineCleanupTimer()
|
||||
saveStats()
|
||||
|
||||
go webhooks.SendStreamStatusEvent(models.StreamStopped)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue