1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

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
This commit is contained in:
Lunny Xiao
2017-12-11 12:37:04 +08:00
committed by Lauris BH
parent c082c3bce3
commit f2e20c81b6
67 changed files with 334 additions and 479 deletions

View File

@@ -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 {