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

@ -8,11 +8,11 @@ import (
"container/list"
"fmt"
"strings"
"time"
"code.gitea.io/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
api "code.gitea.io/sdk/gitea"
"github.com/go-xorm/xorm"
@ -65,17 +65,8 @@ type CommitStatus struct {
Creator *User `xorm:"-"`
CreatorID int64
Created time.Time `xorm:"-"`
CreatedUnix int64 `xorm:"INDEX created"`
Updated time.Time `xorm:"-"`
UpdatedUnix int64 `xorm:"INDEX updated"`
}
// AfterLoad is invoked from XORM after setting the value of a field of
// this object.
func (status *CommitStatus) AfterLoad() {
status.Created = time.Unix(status.CreatedUnix, 0).Local()
status.Updated = time.Unix(status.UpdatedUnix, 0).Local()
CreatedUnix util.TimeStamp `xorm:"INDEX created"`
UpdatedUnix util.TimeStamp `xorm:"INDEX updated"`
}
func (status *CommitStatus) loadRepo(e Engine) (err error) {
@ -106,8 +97,8 @@ func (status *CommitStatus) APIURL() string {
func (status *CommitStatus) APIFormat() *api.Status {
status.loadRepo(x)
apiStatus := &api.Status{
Created: status.Created,
Updated: status.Created,
Created: status.CreatedUnix.AsTime(),
Updated: status.CreatedUnix.AsTime(),
State: api.StatusState(status.State),
TargetURL: status.TargetURL,
Description: status.Description,