mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user