From b679a81cb514bc9a3daf6ebebcaa675368db1596 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Wed, 4 Dec 2019 00:44:45 -0500 Subject: [PATCH] disable some more cache control in debug mode --- hfcs.go | 2 +- honk.go | 2 +- skulduggery.go | 1 - web.go | 29 ++++++++++++++++++----------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/hfcs.go b/hfcs.go index 400b0eb..6768bf2 100644 --- a/hfcs.go +++ b/hfcs.go @@ -44,7 +44,7 @@ type Filter struct { re_rewrite *regexp.Regexp Replace string `json:",omitempty"` Expiration time.Time - Notes string + Notes string } type filtType uint diff --git a/honk.go b/honk.go index d88bdf7..b2c5090 100644 --- a/honk.go +++ b/honk.go @@ -179,7 +179,7 @@ type Honker struct { Handle string Flavor string Combos []string - Meta HonkerMeta + Meta HonkerMeta } type HonkerMeta struct { diff --git a/skulduggery.go b/skulduggery.go index c16f215..c8f669c 100644 --- a/skulduggery.go +++ b/skulduggery.go @@ -21,7 +21,6 @@ import ( "github.com/mattn/go-runewidth" ) - var skinTones = "\U0001F3FB\U0001F3FC\U0001F3FD\U0001F3FE\U0001F3FF" var re_moredumb = regexp.MustCompile("[\U0001f44f\U0001f6a8\U000026a0][" + skinTones + "\ufe0f]*") diff --git a/web.go b/web.go index 68cd870..55aae61 100644 --- a/web.go +++ b/web.go @@ -48,6 +48,8 @@ var readviews *templates.Template var userSep = "u" var honkSep = "h" +var debugMode = false + func getuserstyle(u *login.UserInfo) template.CSS { if u == nil { return "" @@ -223,8 +225,10 @@ func showrss(w http.ResponseWriter, r *http.Request) { modtime = honk.Date } } - w.Header().Set("Cache-Control", "max-age=300") - w.Header().Set("Last-Modified", modtime.Format(http.TimeFormat)) + if !debugMode { + w.Header().Set("Cache-Control", "max-age=300") + w.Header().Set("Last-Modified", modtime.Format(http.TimeFormat)) + } err := feed.Write(w) if err != nil { @@ -874,7 +878,7 @@ func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) { sort.Slice(onts, func(i, j int) bool { return onts[i].Name < onts[j].Name }) - if u == nil { + if u == nil && !debugMode { w.Header().Set("Cache-Control", "max-age=300") } templinfo := getInfo(r) @@ -1093,7 +1097,7 @@ func honkpage(w http.ResponseWriter, u *login.UserInfo, honks []*Honk, templinfo templinfo["TopHID"] = 0 } } - if u == nil { + if u == nil && !debugMode { w.Header().Set("Cache-Control", "max-age=60") } err := readviews.Execute(w, "honkpage.html", templinfo) @@ -1991,7 +1995,9 @@ func avatate(w http.ResponseWriter, r *http.Request) { } func serveasset(w http.ResponseWriter, r *http.Request) { - //w.Header().Set("Cache-Control", "max-age=7776000") + if !debugMode { + w.Header().Set("Cache-Control", "max-age=7776000") + } dir := viewDir if r.URL.Path == "/local.css" { dir = dataDir @@ -2000,7 +2006,9 @@ func serveasset(w http.ResponseWriter, r *http.Request) { } func servehelp(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] - //w.Header().Set("Cache-Control", "max-age=3600") + if !debugMode { + w.Header().Set("Cache-Control", "max-age=3600") + } http.ServeFile(w, r, viewDir+"/docs/"+name) } func servehtml(w http.ResponseWriter, r *http.Request) { @@ -2012,7 +2020,7 @@ func servehtml(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/about" { templinfo["Sensors"] = getSensors() } - if u == nil { + if u == nil && !debugMode { w.Header().Set("Cache-Control", "max-age=60") } err := readviews.Execute(w, r.URL.Path[1:]+".html", templinfo) @@ -2229,9 +2237,8 @@ func serve() { go redeliverator() go tracker() - debug := false - getconfig("debug", &debug) - readviews = templates.Load(debug, + getconfig("debug", &debugMode) + readviews = templates.Load(debugMode, viewDir+"/views/honkpage.html", viewDir+"/views/honkfrags.html", viewDir+"/views/honkers.html", @@ -2249,7 +2256,7 @@ func serve() { viewDir+"/views/onts.html", viewDir+"/views/honkpage.js", ) - if !debug { + if !debugMode { assets := []string{viewDir + "/views/style.css", dataDir + "/views/local.css", viewDir + "/views/honkpage.js"} for _, s := range assets { savedassetparams[s] = getassetparam(s)