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.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.go')
-rw-r--r-- | models/repo.go | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/models/repo.go b/models/repo.go index 77a960deb7..ff0d00308f 100644 --- a/models/repo.go +++ b/models/repo.go @@ -27,6 +27,7 @@ import ( "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/sync" + "code.gitea.io/gitea/modules/util" api "code.gitea.io/sdk/gitea" "github.com/Unknwon/cae/zip" @@ -211,10 +212,8 @@ type Repository struct { Size int64 `xorm:"NOT NULL DEFAULT 0"` IndexerStatus *RepoIndexerStatus `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"` } // AfterLoad is invoked from XORM after setting the values of all fields of this object. @@ -227,8 +226,6 @@ func (repo *Repository) AfterLoad() { repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues repo.NumOpenPulls = repo.NumPulls - repo.NumClosedPulls repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones - repo.Created = time.Unix(repo.CreatedUnix, 0).Local() - repo.Updated = time.Unix(repo.UpdatedUnix, 0) } // MustOwner always returns a valid *User object to avoid @@ -309,8 +306,8 @@ func (repo *Repository) innerAPIFormat(mode AccessMode, isParent bool) *api.Repo Watchers: repo.NumWatches, OpenIssues: repo.NumOpenIssues, DefaultBranch: repo.DefaultBranch, - Created: repo.Created, - Updated: repo.Updated, + Created: repo.CreatedUnix.AsTime(), + Updated: repo.UpdatedUnix.AsTime(), Permissions: permission, } } @@ -1011,10 +1008,10 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err if opts.IsMirror { if _, err = x.InsertOne(&Mirror{ - RepoID: repo.ID, - Interval: setting.Mirror.DefaultInterval, - EnablePrune: true, - NextUpdate: time.Now().Add(setting.Mirror.DefaultInterval), + RepoID: repo.ID, + Interval: setting.Mirror.DefaultInterval, + EnablePrune: true, + NextUpdateUnix: util.TimeStampNow().AddDuration(setting.Mirror.DefaultInterval), }); err != nil { return repo, fmt.Errorf("InsertOne: %v", err) } |