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:
@@ -82,7 +82,7 @@ func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
|
||||
URL: apiLink + com.ToStr(key.ID),
|
||||
Title: key.Name,
|
||||
Fingerprint: key.Fingerprint,
|
||||
Created: key.Created,
|
||||
Created: key.CreatedUnix.AsTime(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ func ToGPGKey(key *models.GPGKey) *api.GPGKey {
|
||||
PrimaryKeyID: k.PrimaryKeyID,
|
||||
KeyID: k.KeyID,
|
||||
PublicKey: k.Content,
|
||||
Created: k.Created,
|
||||
Expires: k.Expired,
|
||||
Created: k.CreatedUnix.AsTime(),
|
||||
Expires: k.ExpiredUnix.AsTime(),
|
||||
CanSign: k.CanSign,
|
||||
CanEncryptComms: k.CanEncryptComms,
|
||||
CanEncryptStorage: k.CanEncryptStorage,
|
||||
@@ -112,8 +112,8 @@ func ToGPGKey(key *models.GPGKey) *api.GPGKey {
|
||||
PrimaryKeyID: key.PrimaryKeyID,
|
||||
KeyID: key.KeyID,
|
||||
PublicKey: key.Content,
|
||||
Created: key.Created,
|
||||
Expires: key.Expired,
|
||||
Created: key.CreatedUnix.AsTime(),
|
||||
Expires: key.ExpiredUnix.AsTime(),
|
||||
Emails: emails,
|
||||
SubsKey: subkeys,
|
||||
CanSign: key.CanSign,
|
||||
@@ -152,8 +152,8 @@ func ToHook(repoLink string, w *models.Webhook) *api.Hook {
|
||||
Active: w.IsActive,
|
||||
Config: config,
|
||||
Events: w.EventsArray(),
|
||||
Updated: w.Updated,
|
||||
Created: w.Created,
|
||||
Updated: w.UpdatedUnix.AsTime(),
|
||||
Created: w.CreatedUnix.AsTime(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
// ListMilestones list all the milestones for a repository
|
||||
@@ -118,10 +119,10 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
|
||||
}
|
||||
|
||||
milestone := &models.Milestone{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
Name: form.Title,
|
||||
Content: form.Description,
|
||||
Deadline: *form.Deadline,
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
Name: form.Title,
|
||||
Content: form.Description,
|
||||
DeadlineUnix: util.TimeStamp(form.Deadline.Unix()),
|
||||
}
|
||||
|
||||
if err := models.NewMilestone(milestone); err != nil {
|
||||
@@ -175,7 +176,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
|
||||
milestone.Content = *form.Description
|
||||
}
|
||||
if form.Deadline != nil && !form.Deadline.IsZero() {
|
||||
milestone.Deadline = *form.Deadline
|
||||
milestone.DeadlineUnix = util.TimeStamp(form.Deadline.Unix())
|
||||
}
|
||||
|
||||
if err := models.UpdateMilestone(milestone); err != nil {
|
||||
|
@@ -97,7 +97,7 @@ func IsWatching(ctx *context.APIContext) {
|
||||
Subscribed: true,
|
||||
Ignored: false,
|
||||
Reason: nil,
|
||||
CreatedAt: ctx.Repo.Repository.Created,
|
||||
CreatedAt: ctx.Repo.Repository.CreatedUnix.AsTime(),
|
||||
URL: subscriptionURL(ctx.Repo.Repository),
|
||||
RepositoryURL: repositoryURL(ctx.Repo.Repository),
|
||||
})
|
||||
@@ -134,7 +134,7 @@ func Watch(ctx *context.APIContext) {
|
||||
Subscribed: true,
|
||||
Ignored: false,
|
||||
Reason: nil,
|
||||
CreatedAt: ctx.Repo.Repository.Created,
|
||||
CreatedAt: ctx.Repo.Repository.CreatedUnix.AsTime(),
|
||||
URL: subscriptionURL(ctx.Repo.Repository),
|
||||
RepositoryURL: repositoryURL(ctx.Repo.Repository),
|
||||
})
|
||||
|
@@ -22,6 +22,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
)
|
||||
|
||||
// HTTP implmentation git smart HTTP protocol
|
||||
@@ -167,7 +168,7 @@ func HTTP(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
token.Updated = time.Now()
|
||||
token.UpdatedUnix = util.TimeStampNow()
|
||||
if err = models.UpdateAccessToken(token); err != nil {
|
||||
ctx.Handle(http.StatusInternalServerError, "UpdateAccessToken", err)
|
||||
}
|
||||
|
@@ -1138,10 +1138,10 @@ func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
|
||||
}
|
||||
|
||||
if err = models.NewMilestone(&models.Milestone{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
Name: form.Title,
|
||||
Content: form.Content,
|
||||
Deadline: deadline,
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
Name: form.Title,
|
||||
Content: form.Content,
|
||||
DeadlineUnix: util.TimeStamp(deadline.Unix()),
|
||||
}); err != nil {
|
||||
ctx.Handle(500, "NewMilestone", err)
|
||||
return
|
||||
@@ -1210,7 +1210,7 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) {
|
||||
}
|
||||
m.Name = form.Title
|
||||
m.Content = form.Content
|
||||
m.Deadline = deadline
|
||||
m.DeadlineUnix = util.TimeStamp(deadline.Unix())
|
||||
if err = models.UpdateMilestone(m); err != nil {
|
||||
ctx.Handle(500, "UpdateMilestone", err)
|
||||
return
|
||||
@@ -1243,7 +1243,7 @@ func ChangeMilestonStatus(ctx *context.Context) {
|
||||
ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=open")
|
||||
case "close":
|
||||
if !m.IsClosed {
|
||||
m.ClosedDate = time.Now()
|
||||
m.ClosedDateUnix = util.TimeStampNow()
|
||||
if err = models.ChangeMilestoneStatus(m, true); err != nil {
|
||||
ctx.Handle(500, "ChangeMilestoneStatus", err)
|
||||
return
|
||||
|
@@ -16,6 +16,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/routers/utils"
|
||||
)
|
||||
|
||||
@@ -119,7 +120,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
|
||||
} else {
|
||||
ctx.Repo.Mirror.EnablePrune = form.EnablePrune
|
||||
ctx.Repo.Mirror.Interval = interval
|
||||
ctx.Repo.Mirror.NextUpdate = time.Now().Add(interval)
|
||||
ctx.Repo.Mirror.NextUpdateUnix = util.TimeStampNow().AddDuration(interval)
|
||||
if err := models.UpdateMirror(ctx.Repo.Mirror); err != nil {
|
||||
ctx.RenderWithErr(ctx.Tr("repo.mirror_interval_invalid"), tplSettingsOptions, &form)
|
||||
return
|
||||
|
Reference in New Issue
Block a user