From 30f39565686b4eee66b0628e4fd9ed6d92a7390c Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Fri, 24 Mar 2017 07:09:41 -0600 Subject: [PATCH] Improve history UI and non-history route speed --- handlers.go | 39 +++++++++++++++++++++++++-------------- templates/index.tmpl | 5 ++++- utils.go | 8 ++++++++ 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/handlers.go b/handlers.go index 77b89bf..913bff1 100755 --- a/handlers.go +++ b/handlers.go @@ -108,10 +108,20 @@ func handlePageRequest(c *gin.Context) { rawHTML = GithubMarkdownToHTML(rawText) } } - versionsInt64 := p.Text.GetMajorSnapshots(60) // get snapshots 60 seconds apart - versionsText := make([]string, len(versionsInt64)) - for i, v := range versionsInt64 { - versionsText[i] = time.Unix(v/1000000000, 0).String() + + // Get history + var versionsInt64 []int64 + var versionsChangeSums []int + var versionsText []string + if command[0:2] == "/h" { + versionsInt64, versionsChangeSums = p.Text.GetMajorSnapshotsAndChangeSums(1) // get snapshots 60 seconds apart + versionsText = make([]string, len(versionsInt64)) + for i, v := range versionsInt64 { + versionsText[i] = time.Unix(v/1000000000, 0).Format("Mon Jan 2 15:04:05 MST 2006") + } + versionsText = reverseSliceString(versionsText) + versionsInt64 = reverseSliceInt64(versionsInt64) + versionsChangeSums = reverseSliceInt(versionsChangeSums) } if command[0:2] == "/r" { @@ -139,16 +149,17 @@ func handlePageRequest(c *gin.Context) { command[0:2] != "/v" && command[0:2] != "/l" && command[0:2] != "/h", - "Page": page, - "RenderedPage": template.HTML([]byte(rawHTML)), - "RawPage": rawText, - "Versions": versionsInt64, - "VersionsText": versionsText, - "IsLocked": p.IsLocked, - "IsEncrypted": p.IsEncrypted, - "ListItems": renderList(rawText), - "Route": "/" + page + command, - "HasDotInName": strings.Contains(page, "."), + "Page": page, + "RenderedPage": template.HTML([]byte(rawHTML)), + "RawPage": rawText, + "Versions": versionsInt64, + "VersionsText": versionsText, + "VersionsChangeSums": versionsChangeSums, + "IsLocked": p.IsLocked, + "IsEncrypted": p.IsEncrypted, + "ListItems": renderList(rawText), + "Route": "/" + page + command, + "HasDotInName": strings.Contains(page, "."), }) } diff --git a/templates/index.tmpl b/templates/index.tmpl index c800fd4..acbd62e 100755 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -438,9 +438,12 @@ {{ if .ViewPage }} {{ .RenderedPage }} {{ end }} {{ if .EditPage }} {{ end }} {{ if .HistoryPage }} +

History

{{ end }} diff --git a/utils.go b/utils.go index c339a92..ebbc385 100644 --- a/utils.go +++ b/utils.go @@ -254,9 +254,17 @@ func reverseSliceInt64(s []int64) []int64 { } return s } + func reverseSliceString(s []string) []string { for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { s[i], s[j] = s[j], s[i] } return s } + +func reverseSliceInt(s []int) []int { + for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 { + s[i], s[j] = s[j], s[i] + } + return s +}