From f2e20c81b66e6a937ecdb686f8d1011371433365 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 11 Dec 2017 12:37:04 +0800 Subject: 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 --- templates/admin/auth/list.tmpl | 4 ++-- templates/admin/monitor.tmpl | 4 ++-- templates/admin/notice.tmpl | 2 +- templates/admin/org/list.tmpl | 2 +- templates/admin/repo/list.tmpl | 2 +- templates/admin/user/list.tmpl | 4 ++-- templates/explore/organizations.tmpl | 2 +- templates/explore/repo_list.tmpl | 2 +- templates/explore/users.tmpl | 2 +- templates/repo/activity.tmpl | 12 ++++++------ templates/repo/branch/list.tmpl | 2 +- templates/repo/issue/list.tmpl | 2 +- templates/repo/issue/milestones.tmpl | 2 +- templates/repo/issue/view_content.tmpl | 2 +- templates/repo/issue/view_content/comments.tmpl | 2 +- templates/repo/issue/view_title.tmpl | 4 ++-- templates/repo/release/list.tmpl | 4 ++-- templates/repo/settings/deploy_keys.tmpl | 2 +- templates/repo/settings/options.tmpl | 2 +- templates/repo/user_cards.tmpl | 2 +- templates/repo/wiki/pages.tmpl | 2 +- templates/user/dashboard/issues.tmpl | 2 +- templates/user/profile.tmpl | 2 +- templates/user/settings/applications.tmpl | 2 +- templates/user/settings/keys_gpg.tmpl | 4 ++-- templates/user/settings/keys_ssh.tmpl | 2 +- 26 files changed, 37 insertions(+), 37 deletions(-) (limited to 'templates') diff --git a/templates/admin/auth/list.tmpl b/templates/admin/auth/list.tmpl index 4e8fb1ea82..60b8f6fbe7 100644 --- a/templates/admin/auth/list.tmpl +++ b/templates/admin/auth/list.tmpl @@ -29,8 +29,8 @@ {{.Name}} {{.TypeName}} - {{DateFmtShort .Updated}} - {{DateFmtShort .Created}} + {{.UpdatedUnix.FormatShort}} + {{.CreatedUnix.FormatShort}} {{end}} diff --git a/templates/admin/monitor.tmpl b/templates/admin/monitor.tmpl index 6cc927d68f..ceca29146e 100644 --- a/templates/admin/monitor.tmpl +++ b/templates/admin/monitor.tmpl @@ -49,8 +49,8 @@ {{.PID}} {{.Description}} - {{DateFmtLong .Start}} - {{TimeSince .Start $.Lang}} + {{.Start.FormatLong}} + {{TimeSinceUnix .Start $.Lang}} {{end}} diff --git a/templates/admin/notice.tmpl b/templates/admin/notice.tmpl index 49e760d2b7..745433d180 100644 --- a/templates/admin/notice.tmpl +++ b/templates/admin/notice.tmpl @@ -29,7 +29,7 @@ {{.ID}} {{$.i18n.Tr .TrStr}} {{SubStr .Description 0 120}}... - {{DateFmtShort .Created}} + {{.CreatedUnix.FormatShort}} {{end}} diff --git a/templates/admin/org/list.tmpl b/templates/admin/org/list.tmpl index 362352b695..141628c5b3 100644 --- a/templates/admin/org/list.tmpl +++ b/templates/admin/org/list.tmpl @@ -33,7 +33,7 @@ {{.NumTeams}} {{.NumMembers}} {{.NumRepos}} - {{DateFmtShort .Created}} + {{.CreatedUnix.FormatShort}} {{end}} diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index aeaecf8dfb..470be359eb 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -36,7 +36,7 @@ {{.NumStars}} {{.NumIssues}} {{SizeFmt .Size}} - {{DateFmtShort .Created}} + {{.CreatedUnix.FormatShort}} {{end}} diff --git a/templates/admin/user/list.tmpl b/templates/admin/user/list.tmpl index 7e06417013..d590526ca3 100644 --- a/templates/admin/user/list.tmpl +++ b/templates/admin/user/list.tmpl @@ -36,9 +36,9 @@ {{.NumRepos}} - {{DateFmtShort .Created }} + {{.CreatedUnix.FormatShort}} {{if .LastLoginUnix}} - {{DateFmtShort .LastLogin }} + {{.LastLoginUnix.FormatShort}} {{else}} {{$.i18n.Tr "admin.users.never_login"}} {{end}} diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index 4b1ab18349..b977da4e4d 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -18,7 +18,7 @@ {{.Website}} {{end}} - {{$.i18n.Tr "user.join_on"}} {{DateFmtShort .Created}} + {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}} diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index 4f264f4831..06e3c0afd8 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -17,7 +17,7 @@ {{if .DescriptionHTML}}

{{.DescriptionHTML}}

{{end}} -

{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Updated $.i18n.Lang}}

+

{{$.i18n.Tr "org.repo_updated"}} {{TimeSinceUnix .UpdatedUnix $.i18n.Lang}}

{{else}}
diff --git a/templates/explore/users.tmpl b/templates/explore/users.tmpl index 0bbbec2ed6..32a36931c7 100644 --- a/templates/explore/users.tmpl +++ b/templates/explore/users.tmpl @@ -18,7 +18,7 @@ {{.Email}} {{end}} - {{$.i18n.Tr "user.join_on"}} {{DateFmtShort .Created}} + {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}}
diff --git a/templates/repo/activity.tmpl b/templates/repo/activity.tmpl index eb761ff492..cd528582fb 100644 --- a/templates/repo/activity.tmpl +++ b/templates/repo/activity.tmpl @@ -86,7 +86,7 @@ {{if not .IsTag}} {{.Title}} {{end}} - {{TimeSince .Created $.Lang}} + {{TimeSinceUnix .CreatedUnix $.Lang}}

{{end}} @@ -102,7 +102,7 @@

{{$.i18n.Tr "repo.activity.merged_prs_label"}}
#{{.Index}} {{.Issue.Title}} - {{TimeSince .Merged $.Lang}} + {{TimeSinceUnix .MergedUnix $.Lang}}

{{end}} @@ -118,7 +118,7 @@

{{$.i18n.Tr "repo.activity.opened_prs_label"}}
#{{.Index}} {{.Issue.Title}} - {{TimeSince .Issue.Created $.Lang}} + {{TimeSinceUnix .Issue.CreatedUnix $.Lang}}

{{end}} @@ -134,7 +134,7 @@

{{$.i18n.Tr "repo.activity.closed_issue_label"}}
#{{.Index}} {{.Title}} - {{TimeSince .Updated $.Lang}} + {{TimeSinceUnix .UpdatedUnix $.Lang}}

{{end}} @@ -150,7 +150,7 @@

{{$.i18n.Tr "repo.activity.new_issue_label"}}
#{{.Index}} {{.Title}} - {{TimeSince .Created $.Lang}} + {{TimeSinceUnix .CreatedUnix $.Lang}}

{{end}} @@ -174,7 +174,7 @@ {{else}} {{.Title}} {{end}} - {{TimeSince .Updated $.Lang}} + {{TimeSinceUnix .UpdatedUnix $.Lang}}

{{end}} diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index a1bbc17677..bc00d0d717 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -39,7 +39,7 @@ {{if .IsDeleted}} {{.Name}} -

{{$.i18n.Tr "repo.branch.deleted_by" .DeletedBranch.DeletedBy.Name}} {{TimeSince .DeletedBranch.Deleted $.i18n.Lang}}

+

{{$.i18n.Tr "repo.branch.deleted_by" .DeletedBranch.DeletedBy.Name}} {{TimeSinceUnix .DeletedBranch.DeletedUnix $.i18n.Lang}}

{{else}} {{.Name}}

{{$.i18n.Tr "org.repo_updated"}} {{TimeSince .Commit.Committer.When $.i18n.Lang}}

diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index bb6170a881..dec2881be8 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -163,7 +163,7 @@
{{range .Issues}} - {{ $timeStr:= TimeSince .Created $.Lang }} + {{ $timeStr:= TimeSinceUnix .CreatedUnix $.Lang }}
  • diff --git a/templates/repo/issue/milestones.tmpl b/templates/repo/issue/milestones.tmpl index 3703301e19..de52bd42f0 100644 --- a/templates/repo/issue/milestones.tmpl +++ b/templates/repo/issue/milestones.tmpl @@ -50,7 +50,7 @@
  • - {{ $closedDate:= TimeSince .ClosedDate $.Lang }} + {{ $closedDate:= TimeSinceUnix .ClosedDateUnix $.Lang }} {{if .IsClosed}} {{$.i18n.Tr "repo.milestones.closed" $closedDate|Str2html}} {{else}} diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 795844d5d3..4343aec9fc 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -8,7 +8,7 @@ {{template "repo/issue/view_title" .}} {{end}} - {{ $createdStr:= TimeSince .Issue.Created $.Lang }} + {{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.Lang }}
    diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index f073fe8108..49a0216e83 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -1,5 +1,5 @@ {{range .Issue.Comments}} - {{ $createdStr:= TimeSince .Created $.Lang }} + {{ $createdStr:= TimeSinceUnix .CreatedUnix $.Lang }} {{if eq .Type 0}} diff --git a/templates/repo/issue/view_title.tmpl b/templates/repo/issue/view_title.tmpl index 4650ba4c80..d69f699ac1 100644 --- a/templates/repo/issue/view_title.tmpl +++ b/templates/repo/issue/view_title.tmpl @@ -26,7 +26,7 @@ {{if .Issue.IsPull}} {{if .Issue.PullRequest.HasMerged}} - {{ $mergedStr:= TimeSince .Issue.PullRequest.Merged $.Lang }} + {{ $mergedStr:= TimeSinceUnix .Issue.PullRequest.MergedUnix $.Lang }} {{.Issue.PullRequest.Merger.Name}} {{$.i18n.Tr "repo.pulls.merged_title_desc" .NumCommits .HeadTarget .BaseTarget $mergedStr | Str2html}} {{else}} @@ -34,7 +34,7 @@ {{$.i18n.Tr "repo.pulls.title_desc" .NumCommits .HeadTarget .BaseTarget | Str2html}} {{end}} {{else}} - {{ $createdStr:= TimeSince .Issue.Created $.Lang }} + {{ $createdStr:= TimeSinceUnix .Issue.CreatedUnix $.Lang }} {{if gt .Issue.Poster.ID 0}} {{$.i18n.Tr "repo.issues.opened_by" $createdStr .Issue.Poster.HomeLink .Issue.Poster.Name | Safe}} diff --git a/templates/repo/release/list.tmpl b/templates/repo/release/list.tmpl index 2fed9ae588..0a3af5a844 100644 --- a/templates/repo/release/list.tmpl +++ b/templates/repo/release/list.tmpl @@ -18,7 +18,7 @@
  • {{if .IsTag}} - {{if .Created}}{{TimeSince .Created $.Lang}}{{end}} + {{if .CreatedUnix}}{{TimeSinceUnix .CreatedUnix $.Lang}}{{end}} {{else}} {{if .IsDraft}} {{$.i18n.Tr "repo.release.draft"}} @@ -55,7 +55,7 @@ {{.Publisher.Name}} - {{if .Created}}{{TimeSince .Created $.Lang}}{{end}} + {{if .CreatedUnix}}{{TimeSinceUnix .CreatedUnix $.Lang}}{{end}} {{$.i18n.Tr "repo.release.ahead" .NumCommitsBehind .Target | Str2html}}

    diff --git a/templates/repo/settings/deploy_keys.tmpl b/templates/repo/settings/deploy_keys.tmpl index caf9f29ce5..3b22be532b 100644 --- a/templates/repo/settings/deploy_keys.tmpl +++ b/templates/repo/settings/deploy_keys.tmpl @@ -31,7 +31,7 @@ {{.Fingerprint}}
    - {{$.i18n.Tr "settings.add_on"}} {{DateFmtShort .Created}} {{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFmtShort .Updated}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}} + {{$.i18n.Tr "settings.add_on"}} {{.CreatedUnix.FormatShort}} {{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{.UpdatedUnix.FormatShort}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}
  • diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index ee738cc9e9..41a91ea26e 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -76,7 +76,7 @@
    - {{.Mirror.Updated}} + {{.Mirror.UpdatedUnix.AsTime}}
    diff --git a/templates/repo/user_cards.tmpl b/templates/repo/user_cards.tmpl index c22caf2576..5288d05ef9 100644 --- a/templates/repo/user_cards.tmpl +++ b/templates/repo/user_cards.tmpl @@ -16,7 +16,7 @@ {{else if .Location}} {{.Location}} {{else}} - {{$.i18n.Tr "user.join_on"}} {{DateFmtShort .Created}} + {{$.i18n.Tr "user.join_on"}} {{.CreatedUnix.FormatShort}} {{end}}
    diff --git a/templates/repo/wiki/pages.tmpl b/templates/repo/wiki/pages.tmpl index 8437e9b6b3..2829b61374 100644 --- a/templates/repo/wiki/pages.tmpl +++ b/templates/repo/wiki/pages.tmpl @@ -18,7 +18,7 @@ {{.Name}} - {{$timeSince := TimeSince .Updated $.Lang}} + {{$timeSince := TimeSinceUnix .UpdatedUnix $.Lang}} {{$.i18n.Tr "repo.wiki.last_updated" $timeSince | Safe}} {{end}} diff --git a/templates/user/dashboard/issues.tmpl b/templates/user/dashboard/issues.tmpl index 954b868214..cf2e10885b 100644 --- a/templates/user/dashboard/issues.tmpl +++ b/templates/user/dashboard/issues.tmpl @@ -59,7 +59,7 @@
    {{range .Issues}} - {{ $timeStr:= TimeSince .Created $.Lang }} + {{ $timeStr:= TimeSinceUnix .CreatedUnix $.Lang }}
  • {{if not $.RepoID}}{{.Repo.FullName}}{{end}}#{{.Index}}
    {{.Title}} diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 22a7f96eda..e89a4aa378 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -42,7 +42,7 @@
  • {{end}} {{end}} -
  • {{.i18n.Tr "user.join_on"}} {{DateFmtShort .Owner.Created}}
  • +
  • {{.i18n.Tr "user.join_on"}} {{.Owner.CreatedUnix.FormatShort}}
  • diff --git a/templates/user/settings/applications.tmpl b/templates/user/settings/applications.tmpl index d4d19dcedf..93b2f992df 100644 --- a/templates/user/settings/applications.tmpl +++ b/templates/user/settings/applications.tmpl @@ -25,7 +25,7 @@
    {{.Name}}
    - {{$.i18n.Tr "settings.add_on"}} {{DateFmtShort .Created}} {{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFmtShort .Updated}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}} + {{$.i18n.Tr "settings.add_on"}} {{.CreatedUnix.FormatShort}} {{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{.UpdatedUnix.FormatShort}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}
  • diff --git a/templates/user/settings/keys_gpg.tmpl b/templates/user/settings/keys_gpg.tmpl index 80b2b27523..3ae4249c8d 100644 --- a/templates/user/settings/keys_gpg.tmpl +++ b/templates/user/settings/keys_gpg.tmpl @@ -24,9 +24,9 @@ {{$.i18n.Tr "settings.subkeys"}}: {{range .SubsKey}} {{.KeyID}} {{end}}
    - {{$.i18n.Tr "settings.add_on"}} {{DateFmtShort .Added}} + {{$.i18n.Tr "settings.add_on"}} {{.AddedUnix.FormatShort}} - - {{if not .Expired.IsZero }}{{$.i18n.Tr "settings.valid_until"}} {{DateFmtShort .Expired}}{{else}}{{$.i18n.Tr "settings.valid_forever"}}{{end}} + {{if .ExpiredUnix}}{{$.i18n.Tr "settings.valid_until"}} {{.ExpiredUnix.FormatShort}}{{else}}{{$.i18n.Tr "settings.valid_forever"}}{{end}}
    diff --git a/templates/user/settings/keys_ssh.tmpl b/templates/user/settings/keys_ssh.tmpl index bc93d3e4ef..e954472ff9 100644 --- a/templates/user/settings/keys_ssh.tmpl +++ b/templates/user/settings/keys_ssh.tmpl @@ -27,7 +27,7 @@ {{.Fingerprint}}
    - {{$.i18n.Tr "settings.add_on"}} {{DateFmtShort .Created}} {{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{DateFmtShort .Updated}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}} + {{$.i18n.Tr "settings.add_on"}} {{.CreatedUnix.FormatShort}} {{if .HasUsed}}{{$.i18n.Tr "settings.last_used"}} {{.UpdatedUnix.FormatShort}}{{else}}{{$.i18n.Tr "settings.no_activity"}}{{end}}
    -- cgit v1.2.3