summaryrefslogtreecommitdiffstats
path: root/models/status.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/status.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/status.go')
-rw-r--r--models/status.go19
1 files changed, 5 insertions, 14 deletions
diff --git a/models/status.go b/models/status.go
index e2e8adb77b..3146f8d303 100644
--- a/models/status.go
+++ b/models/status.go
@@ -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,