summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2022-04-25 20:45:22 +0000
committerGitHub <noreply@github.com>2022-04-25 22:45:22 +0200
commit4e912a61c8083498427eba930a0a99eba91be0ed (patch)
tree94bf0d7fbcc990877cdb34541639a9a8642ab7d8 /routers
parent1ebb30e41bf3b44404d7d03a5541729762c226b5 (diff)
downloadgitea-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 'routers')
-rw-r--r--routers/web/events/events.go33
-rw-r--r--routers/web/repo/issue_stopwatch.go14
2 files changed, 14 insertions, 33 deletions
diff --git a/routers/web/events/events.go b/routers/web/events/events.go
index 02d20550af..d8c6f38d02 100644
--- a/routers/web/events/events.go
+++ b/routers/web/events/events.go
@@ -8,15 +8,10 @@ import (
"net/http"
"time"
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/convert"
"code.gitea.io/gitea/modules/eventsource"
"code.gitea.io/gitea/modules/graceful"
- "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/web/auth"
)
@@ -71,8 +66,6 @@ func Events(ctx *context.Context) {
timer := time.NewTicker(30 * time.Second)
- stopwatchTimer := time.NewTicker(setting.UI.Notification.MinTimeout)
-
loop:
for {
select {
@@ -93,32 +86,6 @@ loop:
case <-shutdownCtx.Done():
go unregister()
break loop
- case <-stopwatchTimer.C:
- sws, err := models.GetUserStopwatches(ctx.Doer.ID, db.ListOptions{})
- if err != nil {
- log.Error("Unable to GetUserStopwatches: %v", err)
- continue
- }
- apiSWs, err := convert.ToStopWatches(sws)
- 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
- }
- _, err = (&eventsource.Event{
- Name: "stopwatches",
- Data: string(dataBs),
- }).WriteTo(ctx.Resp)
- if err != nil {
- log.Error("Unable to write to EventStream for user %s: %v", ctx.Doer.Name, err)
- go unregister()
- break loop
- }
- ctx.Resp.Flush()
case event, ok := <-messageChan:
if !ok {
break loop
diff --git a/routers/web/repo/issue_stopwatch.go b/routers/web/repo/issue_stopwatch.go
index 7ef80e7725..83e4ecedbf 100644
--- a/routers/web/repo/issue_stopwatch.go
+++ b/routers/web/repo/issue_stopwatch.go
@@ -9,7 +9,9 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/eventsource"
)
// IssueStopwatch creates or stops a stopwatch for the given issue.
@@ -59,6 +61,18 @@ func CancelStopwatch(c *context.Context) {
return
}
+ stopwatches, err := models.GetUserStopwatches(c.Doer.ID, db.ListOptions{})
+ if err != nil {
+ c.ServerError("GetUserStopwatches", err)
+ return
+ }
+ if len(stopwatches) == 0 {
+ eventsource.GetManager().SendMessage(c.Doer.ID, &eventsource.Event{
+ Name: "stopwatches",
+ Data: "{}",
+ })
+ }
+
url := issue.HTMLURL()
c.Redirect(url, http.StatusSeeOther)
}