summaryrefslogtreecommitdiffstats
path: root/models/issue_stopwatch.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-12-11 12:37:04 +0800
committerLauris BH <lauris@nix.lv>2017-12-11 06:37:04 +0200
commitf2e20c81b66e6a937ecdb686f8d1011371433365 (patch)
tree490e5af82aefdd25de5d90225b083ecb3ed11e5f /models/issue_stopwatch.go
parentc082c3bce35d6d5d829a1e516b9bbf45b6d49bdc (diff)
downloadgitea-f2e20c81b66e6a937ecdb686f8d1011371433365.tar.gz
gitea-f2e20c81b66e6a937ecdb686f8d1011371433365.zip
Refactor struct's time to remove unnecessary memory usage (#3142)
* refactor struct's time to remove unnecessary memory usage * use AsTimePtr simple code * fix tests * fix time compare * fix template on gpg * use AddDuration instead of Add
Diffstat (limited to 'models/issue_stopwatch.go')
-rw-r--r--models/issue_stopwatch.go25
1 files changed, 7 insertions, 18 deletions
diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go
index b136c511f4..92b1bb9a5f 100644
--- a/models/issue_stopwatch.go
+++ b/models/issue_stopwatch.go
@@ -7,26 +7,16 @@ package models
import (
"fmt"
"time"
+
+ "code.gitea.io/gitea/modules/util"
)
// Stopwatch represents a stopwatch for time tracking.
type Stopwatch struct {
- ID int64 `xorm:"pk autoincr"`
- IssueID int64 `xorm:"INDEX"`
- UserID int64 `xorm:"INDEX"`
- Created time.Time `xorm:"-"`
- CreatedUnix int64
-}
-
-// BeforeInsert will be invoked by XORM before inserting a record
-// representing this object.
-func (s *Stopwatch) BeforeInsert() {
- s.CreatedUnix = time.Now().Unix()
-}
-
-// AfterLoad is invoked from XORM after setting the values of all fields of this object.
-func (s *Stopwatch) AfterLoad() {
- s.Created = time.Unix(s.CreatedUnix, 0).Local()
+ ID int64 `xorm:"pk autoincr"`
+ IssueID int64 `xorm:"INDEX"`
+ UserID int64 `xorm:"INDEX"`
+ CreatedUnix util.TimeStamp `xorm:"created"`
}
func getStopwatch(e Engine, userID, issueID int64) (sw *Stopwatch, exists bool, err error) {
@@ -61,7 +51,7 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error {
}
if exists {
// Create tracked time out of the time difference between start date and actual date
- timediff := time.Now().Unix() - sw.CreatedUnix
+ timediff := time.Now().Unix() - int64(sw.CreatedUnix)
// Create TrackedTime
tt := &TrackedTime{
@@ -92,7 +82,6 @@ func CreateOrStopIssueStopwatch(user *User, issue *Issue) error {
sw = &Stopwatch{
UserID: user.ID,
IssueID: issue.ID,
- Created: time.Now(),
}
if _, err := x.Insert(sw); err != nil {