mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08: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:
		@@ -9,7 +9,6 @@ import (
 | 
			
		||||
	"path"
 | 
			
		||||
	"sort"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	api "code.gitea.io/sdk/gitea"
 | 
			
		||||
	"github.com/Unknwon/com"
 | 
			
		||||
@@ -45,31 +44,15 @@ type Issue struct {
 | 
			
		||||
	NumComments     int
 | 
			
		||||
	Ref             string
 | 
			
		||||
 | 
			
		||||
	Deadline     time.Time `xorm:"-"`
 | 
			
		||||
	DeadlineUnix int64     `xorm:"INDEX"`
 | 
			
		||||
	Created      time.Time `xorm:"-"`
 | 
			
		||||
	CreatedUnix  int64     `xorm:"INDEX created"`
 | 
			
		||||
	Updated      time.Time `xorm:"-"`
 | 
			
		||||
	UpdatedUnix  int64     `xorm:"INDEX updated"`
 | 
			
		||||
	DeadlineUnix util.TimeStamp `xorm:"INDEX"`
 | 
			
		||||
	CreatedUnix  util.TimeStamp `xorm:"INDEX created"`
 | 
			
		||||
	UpdatedUnix  util.TimeStamp `xorm:"INDEX updated"`
 | 
			
		||||
 | 
			
		||||
	Attachments []*Attachment `xorm:"-"`
 | 
			
		||||
	Comments    []*Comment    `xorm:"-"`
 | 
			
		||||
	Reactions   ReactionList  `xorm:"-"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// BeforeUpdate is invoked from XORM before updating this object.
 | 
			
		||||
func (issue *Issue) BeforeUpdate() {
 | 
			
		||||
	issue.DeadlineUnix = issue.Deadline.Unix()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AfterLoad is invoked from XORM after setting the value of a field of
 | 
			
		||||
// this object.
 | 
			
		||||
func (issue *Issue) AfterLoad() {
 | 
			
		||||
	issue.Deadline = time.Unix(issue.DeadlineUnix, 0).Local()
 | 
			
		||||
	issue.Created = time.Unix(issue.CreatedUnix, 0).Local()
 | 
			
		||||
	issue.Updated = time.Unix(issue.UpdatedUnix, 0).Local()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (issue *Issue) loadRepo(e Engine) (err error) {
 | 
			
		||||
	if issue.Repo == nil {
 | 
			
		||||
		issue.Repo, err = getRepositoryByID(e, issue.RepoID)
 | 
			
		||||
@@ -307,8 +290,8 @@ func (issue *Issue) APIFormat() *api.Issue {
 | 
			
		||||
		Labels:   apiLabels,
 | 
			
		||||
		State:    issue.State(),
 | 
			
		||||
		Comments: issue.NumComments,
 | 
			
		||||
		Created:  issue.Created,
 | 
			
		||||
		Updated:  issue.Updated,
 | 
			
		||||
		Created:  issue.CreatedUnix.AsTime(),
 | 
			
		||||
		Updated:  issue.UpdatedUnix.AsTime(),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if issue.Milestone != nil {
 | 
			
		||||
@@ -322,7 +305,7 @@ func (issue *Issue) APIFormat() *api.Issue {
 | 
			
		||||
			HasMerged: issue.PullRequest.HasMerged,
 | 
			
		||||
		}
 | 
			
		||||
		if issue.PullRequest.HasMerged {
 | 
			
		||||
			apiIssue.PullRequest.Merged = &issue.PullRequest.Merged
 | 
			
		||||
			apiIssue.PullRequest.Merged = issue.PullRequest.MergedUnix.AsTimePtr()
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user