diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-12-11 12:37:04 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-12-11 06:37:04 +0200 |
commit | f2e20c81b66e6a937ecdb686f8d1011371433365 (patch) | |
tree | 490e5af82aefdd25de5d90225b083ecb3ed11e5f /models/issue.go | |
parent | c082c3bce35d6d5d829a1e516b9bbf45b6d49bdc (diff) | |
download | gitea-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.go')
-rw-r--r-- | models/issue.go | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/models/issue.go b/models/issue.go index 2119dcefd9..7cea3b92a2 100644 --- a/models/issue.go +++ b/models/issue.go @@ -9,7 +9,6 @@ import ( "path" "sort" "strings" - "time" api "code.gitea.io/sdk/gitea" "github.com/Unknwon/com" @@ -45,31 +44,15 @@ type Issue struct { NumComments int Ref string - Deadline time.Time `xorm:"-"` - DeadlineUnix int64 `xorm:"INDEX"` - Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX created"` - Updated time.Time `xorm:"-"` - UpdatedUnix int64 `xorm:"INDEX updated"` + DeadlineUnix util.TimeStamp `xorm:"INDEX"` + CreatedUnix util.TimeStamp `xorm:"INDEX created"` + UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` Attachments []*Attachment `xorm:"-"` Comments []*Comment `xorm:"-"` Reactions ReactionList `xorm:"-"` } -// BeforeUpdate is invoked from XORM before updating this object. -func (issue *Issue) BeforeUpdate() { - issue.DeadlineUnix = issue.Deadline.Unix() -} - -// AfterLoad is invoked from XORM after setting the value of a field of -// this object. -func (issue *Issue) AfterLoad() { - issue.Deadline = time.Unix(issue.DeadlineUnix, 0).Local() - issue.Created = time.Unix(issue.CreatedUnix, 0).Local() - issue.Updated = time.Unix(issue.UpdatedUnix, 0).Local() -} - func (issue *Issue) loadRepo(e Engine) (err error) { if issue.Repo == nil { issue.Repo, err = getRepositoryByID(e, issue.RepoID) @@ -307,8 +290,8 @@ func (issue *Issue) APIFormat() *api.Issue { Labels: apiLabels, State: issue.State(), Comments: issue.NumComments, - Created: issue.Created, - Updated: issue.Updated, + Created: issue.CreatedUnix.AsTime(), + Updated: issue.UpdatedUnix.AsTime(), } if issue.Milestone != nil { @@ -322,7 +305,7 @@ func (issue *Issue) APIFormat() *api.Issue { HasMerged: issue.PullRequest.HasMerged, } if issue.PullRequest.HasMerged { - apiIssue.PullRequest.Merged = &issue.PullRequest.Merged + apiIssue.PullRequest.Merged = issue.PullRequest.MergedUnix.AsTimePtr() } } |