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_comment.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_comment.go')
-rw-r--r-- | models/issue_comment.go | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/models/issue_comment.go b/models/issue_comment.go index aabeb9c8d4..2f4ddd63ec 100644 --- a/models/issue_comment.go +++ b/models/issue_comment.go @@ -7,7 +7,6 @@ package models import ( "fmt" "strings" - "time" "github.com/Unknwon/com" "github.com/go-xorm/builder" @@ -17,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/util" ) // CommentType defines whether a comment is just a simple comment, an action (like close) or a reference. @@ -98,10 +98,8 @@ type Comment struct { Content string `xorm:"TEXT"` RenderedContent string `xorm:"-"` - Created time.Time `xorm:"-"` - CreatedUnix int64 `xorm:"INDEX created"` - Updated time.Time `xorm:"-"` - UpdatedUnix int64 `xorm:"INDEX updated"` + CreatedUnix util.TimeStamp `xorm:"INDEX created"` + UpdatedUnix util.TimeStamp `xorm:"INDEX updated"` // Reference issue in commit message CommitSHA string `xorm:"VARCHAR(40)"` @@ -115,9 +113,6 @@ type Comment struct { // AfterLoad is invoked from XORM after setting the values of all fields of this object. func (c *Comment) AfterLoad(session *xorm.Session) { - c.Created = time.Unix(c.CreatedUnix, 0).Local() - c.Updated = time.Unix(c.UpdatedUnix, 0).Local() - var err error c.Attachments, err = getAttachmentsByCommentID(session, c.ID) if err != nil { @@ -191,8 +186,8 @@ func (c *Comment) APIFormat() *api.Comment { IssueURL: c.IssueURL(), PRURL: c.PRURL(), Body: c.Content, - Created: c.Created, - Updated: c.Updated, + Created: c.CreatedUnix.AsTime(), + Updated: c.UpdatedUnix.AsTime(), } } |