diff --git a/admin_votes.go b/admin_votes.go index c0b63ef..45feb4d 100644 --- a/admin_votes.go +++ b/admin_votes.go @@ -11,10 +11,6 @@ func handleAdminVotes(w http.ResponseWriter, req *http.Request, page *pageData) page.SubTitle = "Votes" switch vars["function"] { default: - type votesPageData struct { - Votes []Vote - } - page.TemplateData = votesPageData{Votes: dbGetAllVotes()} page.show("admin-votes.html", w) } } diff --git a/main.go b/main.go index 4648c83..95077ac 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,8 @@ type siteData struct { DevMode bool CurrentJam string + + AllVotes []Vote } // pageData is stuff that changes per request @@ -199,6 +201,9 @@ func initialize() { } else { fmt.Println(err.Error()) } + + // Load all votes into memory + site.AllVotes = dbGetAllVotes() } func loggingHandler(h http.Handler) http.Handler { diff --git a/public_endpoints.go b/public_endpoints.go index 4bf62e5..266d5b6 100644 --- a/public_endpoints.go +++ b/public_endpoints.go @@ -57,5 +57,8 @@ func handlePublicSaveVote(w http.ResponseWriter, req *http.Request) { if err := dbSaveVote(page.ClientId, timestamp, voteSlice); err != nil { page.session.setFlashMessage("Error Saving Vote: "+err.Error(), "error") } + if newVote, err := dbGetVote(page.ClientId, timestamp); err == nil { + site.AllVotes = append(site.AllVotes, *newVote) + } redirect("/", w, req) } diff --git a/templates/admin-votes.html b/templates/admin-votes.html index 9aebbf5..9622561 100644 --- a/templates/admin-votes.html +++ b/templates/admin-votes.html @@ -5,7 +5,7 @@
- {{ range $i, $v, := .TemplateData.Votes }} + {{ range $i, $v, := .Site.AllVotes }}