Skip to content

Commit c771b8d

Browse files
author
Gusted
committed
Improve Stopwatch behavior
- 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.
1 parent 1563a45 commit c771b8d

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

routers/web/events/events.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func Events(ctx *context.Context) {
7272
timer := time.NewTicker(30 * time.Second)
7373

7474
stopwatchTimer := time.NewTicker(setting.UI.Notification.MinTimeout)
75+
prevStopwatchEmpty := false
7576

7677
loop:
7778
for {
@@ -99,6 +100,14 @@ loop:
99100
log.Error("Unable to GetUserStopwatches: %v", err)
100101
continue
101102
}
103+
if len(sws) == 0 {
104+
if prevStopwatchEmpty {
105+
continue
106+
}
107+
prevStopwatchEmpty = true
108+
} else {
109+
prevStopwatchEmpty = false
110+
}
102111
apiSWs, err := convert.ToStopWatches(sws)
103112
if err != nil {
104113
log.Error("Unable to APIFormat stopwatches: %v", err)

web_src/js/features/stopwatch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ function updateStopwatchData(data) {
127127
const watch = data[0];
128128
const btnEl = $('.active-stopwatch-trigger');
129129
if (!watch) {
130+
clearInterval(updateTimeInterval);
130131
btnEl.addClass('hidden');
131132
} else {
132133
const {repo_owner_name, repo_name, issue_index, seconds} = watch;

0 commit comments

Comments
 (0)