aboutsummaryrefslogtreecommitdiffstats
path: root/models/issue_milestone.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_milestone.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_milestone.go')
-rw-r--r--models/issue_milestone.go31
1 files changed, 11 insertions, 20 deletions
diff --git a/models/issue_milestone.go b/models/issue_milestone.go
index 13cbe7ffbd..b4ebabf57e 100644
--- a/models/issue_milestone.go
+++ b/models/issue_milestone.go
@@ -5,9 +5,8 @@
package models
import (
- "time"
-
"code.gitea.io/gitea/modules/setting"
+ "code.gitea.io/gitea/modules/util"
api "code.gitea.io/sdk/gitea"
"github.com/go-xorm/xorm"
@@ -27,16 +26,14 @@ type Milestone struct {
Completeness int // Percentage(1-100).
IsOverDue bool `xorm:"-"`
- DeadlineString string `xorm:"-"`
- Deadline time.Time `xorm:"-"`
- DeadlineUnix int64
- ClosedDate time.Time `xorm:"-"`
- ClosedDateUnix int64
+ DeadlineString string `xorm:"-"`
+ DeadlineUnix util.TimeStamp
+ ClosedDateUnix util.TimeStamp
}
// BeforeInsert is invoked from XORM before inserting an object of this type.
func (m *Milestone) BeforeInsert() {
- m.DeadlineUnix = m.Deadline.Unix()
+ m.DeadlineUnix = util.TimeStampNow()
}
// BeforeUpdate is invoked from XORM before updating this object.
@@ -46,26 +43,20 @@ func (m *Milestone) BeforeUpdate() {
} else {
m.Completeness = 0
}
-
- m.DeadlineUnix = m.Deadline.Unix()
- m.ClosedDateUnix = m.ClosedDate.Unix()
}
// AfterLoad is invoked from XORM after setting the value of a field of
// this object.
func (m *Milestone) AfterLoad() {
m.NumOpenIssues = m.NumIssues - m.NumClosedIssues
- m.Deadline = time.Unix(m.DeadlineUnix, 0).Local()
- if m.Deadline.Year() == 9999 {
+ if m.DeadlineUnix.Year() == 9999 {
return
}
- m.DeadlineString = m.Deadline.Format("2006-01-02")
- if time.Now().Local().After(m.Deadline) {
+ m.DeadlineString = m.DeadlineUnix.Format("2006-01-02")
+ if util.TimeStampNow() >= m.DeadlineUnix {
m.IsOverDue = true
}
-
- m.ClosedDate = time.Unix(m.ClosedDateUnix, 0).Local()
}
// State returns string representation of milestone status.
@@ -87,10 +78,10 @@ func (m *Milestone) APIFormat() *api.Milestone {
ClosedIssues: m.NumClosedIssues,
}
if m.IsClosed {
- apiMilestone.Closed = &m.ClosedDate
+ apiMilestone.Closed = m.ClosedDateUnix.AsTimePtr()
}
- if m.Deadline.Year() < 9999 {
- apiMilestone.Deadline = &m.Deadline
+ if m.DeadlineUnix.Year() < 9999 {
+ apiMilestone.Deadline = m.DeadlineUnix.AsTimePtr()
}
return apiMilestone
}