diff options
author | Gusted <williamzijl7@hotmail.com> | 2022-04-25 20:45:22 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-25 22:45:22 +0200 |
commit | 4e912a61c8083498427eba930a0a99eba91be0ed (patch) | |
tree | 94bf0d7fbcc990877cdb34541639a9a8642ab7d8 /modules/eventsource | |
parent | 1ebb30e41bf3b44404d7d03a5541729762c226b5 (diff) | |
download | gitea-4e912a61c8083498427eba930a0a99eba91be0ed.tar.gz gitea-4e912a61c8083498427eba930a0a99eba91be0ed.zip |
Improve Stopwatch behavior (#18930)
- Don't send empty stopwatch over and over again, only send once.
- Stop interval to update stopwatch's timer when there is no more stopwatch.
Diffstat (limited to 'modules/eventsource')
-rw-r--r-- | modules/eventsource/manager_run.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/eventsource/manager_run.go b/modules/eventsource/manager_run.go index 9af5c9e78a..127979ad63 100644 --- a/modules/eventsource/manager_run.go +++ b/modules/eventsource/manager_run.go @@ -9,7 +9,9 @@ import ( "time" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/graceful" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" @@ -80,6 +82,31 @@ loop: }) } then = now + + if setting.Service.EnableTimetracking { + usersStopwatches, err := models.GetUIDsAndStopwatch() + if err != nil { + log.Error("Unable to get GetUIDsAndStopwatch: %v", err) + return + } + + for _, userStopwatches := range usersStopwatches { + apiSWs, err := convert.ToStopWatches(userStopwatches.StopWatches) + if err != nil { + log.Error("Unable to APIFormat stopwatches: %v", err) + continue + } + dataBs, err := json.Marshal(apiSWs) + if err != nil { + log.Error("Unable to marshal stopwatches: %v", err) + continue + } + m.SendMessage(userStopwatches.UserID, &Event{ + Name: "stopwatches", + Data: string(dataBs), + }) + } + } } } m.UnregisterAll() |