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/repo_mirror.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/repo_mirror.go')
-rw-r--r-- | models/repo_mirror.go | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/models/repo_mirror.go b/models/repo_mirror.go index f52b3eb452..197889e19a 100644 --- a/models/repo_mirror.go +++ b/models/repo_mirror.go @@ -31,10 +31,8 @@ type Mirror struct { Interval time.Duration EnablePrune bool `xorm:"NOT NULL DEFAULT true"` - Updated time.Time `xorm:"-"` - UpdatedUnix int64 `xorm:"INDEX"` - NextUpdate time.Time `xorm:"-"` - NextUpdateUnix int64 `xorm:"INDEX"` + UpdatedUnix util.TimeStamp `xorm:"INDEX"` + NextUpdateUnix util.TimeStamp `xorm:"INDEX"` address string `xorm:"-"` } @@ -42,16 +40,8 @@ type Mirror struct { // BeforeInsert will be invoked by XORM before inserting a record func (m *Mirror) BeforeInsert() { if m != nil { - m.UpdatedUnix = time.Now().Unix() - m.NextUpdateUnix = m.NextUpdate.Unix() - } -} - -// BeforeUpdate is invoked from XORM before updating this object. -func (m *Mirror) BeforeUpdate() { - if m != nil { - m.UpdatedUnix = m.Updated.Unix() - m.NextUpdateUnix = m.NextUpdate.Unix() + m.UpdatedUnix = util.TimeStampNow() + m.NextUpdateUnix = util.TimeStampNow() } } @@ -66,14 +56,11 @@ func (m *Mirror) AfterLoad(session *xorm.Session) { if err != nil { log.Error(3, "getRepositoryByID[%d]: %v", m.ID, err) } - - m.Updated = time.Unix(m.UpdatedUnix, 0).Local() - m.NextUpdate = time.Unix(m.NextUpdateUnix, 0).Local() } // ScheduleNextUpdate calculates and sets next update time. func (m *Mirror) ScheduleNextUpdate() { - m.NextUpdate = time.Now().Add(m.Interval) + m.NextUpdateUnix = util.TimeStampNow().AddDuration(m.Interval) } func remoteAddress(repoPath string) (string, error) { @@ -193,7 +180,7 @@ func (m *Mirror) runSync() bool { } } - m.Updated = time.Now() + m.UpdatedUnix = util.TimeStampNow() return true } |