summaryrefslogtreecommitdiffstats
path: root/models/issue_stopwatch.go
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 /models/issue_stopwatch.go
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 'models/issue_stopwatch.go')
-rw-r--r--models/issue_stopwatch.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go
index 80dd44642e..81459ba446 100644
--- a/models/issue_stopwatch.go
+++ b/models/issue_stopwatch.go
@@ -66,6 +66,38 @@ func getStopwatch(ctx context.Context, userID, issueID int64) (sw *Stopwatch, ex
return
}
+// UserIDCount is a simple coalition of UserID and Count
+type UserStopwatch struct {
+ UserID int64
+ StopWatches []*Stopwatch
+}
+
+// GetUIDsAndNotificationCounts between the two provided times
+func GetUIDsAndStopwatch() ([]*UserStopwatch, error) {
+ sws := []*Stopwatch{}
+ if err := db.GetEngine(db.DefaultContext).Find(&sws); err != nil {
+ return nil, err
+ }
+ if len(sws) == 0 {
+ return []*UserStopwatch{}, nil
+ }
+
+ lastUserID := int64(-1)
+ res := []*UserStopwatch{}
+ for _, sw := range sws {
+ if lastUserID == sw.UserID {
+ lastUserStopwatch := res[len(res)-1]
+ lastUserStopwatch.StopWatches = append(lastUserStopwatch.StopWatches, sw)
+ } else {
+ res = append(res, &UserStopwatch{
+ UserID: sw.UserID,
+ StopWatches: []*Stopwatch{sw},
+ })
+ }
+ }
+ return res, nil
+}
+
// GetUserStopwatches return list of all stopwatches of a user
func GetUserStopwatches(userID int64, listOptions db.ListOptions) ([]*Stopwatch, error) {
sws := make([]*Stopwatch, 0, 8)