summary refs log tree commit diff stats
path: root/svc/cache.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-12 21:35:52 -0400
committerGitHub <noreply@github.com>2019-06-12 21:35:52 -0400
commita2d5115725dea018edb8a8dbaf3c622fabe2680e (patch)
treecacbd836373239b0b3f5b8ce25fc642ce43179a6 /svc/cache.go
parentbe76daaa8b4e6f6d5f60c79ecd84a8d034cbe351 (diff)
parentfbfe7f582979c9db9089187b7316013bd0b1d423 (diff)
downloadgetwtxt-a2d5115725dea018edb8a8dbaf3c622fabe2680e.tar.gz
Merge pull request #8 from getwtxt/multiple-logfiles
Using separate log files for requests and other messages
Diffstat (limited to 'svc/cache.go')
-rw-r--r--svc/cache.go35
1 files changed, 10 insertions, 25 deletions
diff --git a/svc/cache.go b/svc/cache.go
index d3ac872..7bad078 100644
--- a/svc/cache.go
+++ b/svc/cache.go
@@ -41,10 +41,8 @@ type staticAssets struct {
 // file's "Instance" section.
 func initTemplates() *template.Template {
 	confObj.Mu.RLock()
-	assetsDir := confObj.AssetsDir
-	confObj.Mu.RUnlock()
-
-	return template.Must(template.ParseFiles(assetsDir + "/tmpl/index.html"))
+	defer confObj.Mu.RUnlock()
+	return template.Must(template.ParseFiles(confObj.AssetsDir + "/tmpl/index.html"))
 }
 
 func cacheUpdate() {
@@ -73,44 +71,31 @@ func cacheUpdate() {
 // pulled back into memory from disk.
 func pingAssets() {
 	confObj.Mu.RLock()
-	assetsDir := confObj.AssetsDir
-	confObj.Mu.RUnlock()
+	defer confObj.Mu.RUnlock()
+	staticCache.mu.Lock()
+	defer staticCache.mu.Unlock()
 
-	cssStat, err := os.Stat(assetsDir + "/style.css")
+	cssStat, err := os.Stat(confObj.AssetsDir + "/style.css")
 	errLog("", err)
-
-	indexStat, err := os.Stat(assetsDir + "/tmpl/index.html")
+	indexStat, err := os.Stat(confObj.AssetsDir + "/tmpl/index.html")
 	errLog("", err)
 
-	staticCache.mu.RLock()
-	indexMod := staticCache.indexMod
-	cssMod := staticCache.cssMod
-	staticCache.mu.RUnlock()
-
-	if !indexMod.Equal(indexStat.ModTime()) {
+	if !staticCache.indexMod.Equal(indexStat.ModTime()) {
 		tmpls = initTemplates()
 
 		var b []byte
 		buf := bytes.NewBuffer(b)
-
-		confObj.Mu.RLock()
 		errLog("", tmpls.ExecuteTemplate(buf, "index.html", confObj.Instance))
-		confObj.Mu.RUnlock()
 
-		staticCache.mu.Lock()
 		staticCache.index = buf.Bytes()
 		staticCache.indexMod = indexStat.ModTime()
-		staticCache.mu.Unlock()
 	}
 
-	if !cssMod.Equal(cssStat.ModTime()) {
-
-		css, err := ioutil.ReadFile(assetsDir + "/style.css")
+	if !staticCache.cssMod.Equal(cssStat.ModTime()) {
+		css, err := ioutil.ReadFile(confObj.AssetsDir + "/style.css")
 		errLog("", err)
 
-		staticCache.mu.Lock()
 		staticCache.css = css
 		staticCache.cssMod = cssStat.ModTime()
-		staticCache.mu.Unlock()
 	}
 }
<boothj5@gmail.com> 2014-01-19 17:20:31 +0000 Use defaults for /statuses commands' href='/danisanti/profani-tty/commit/tests/test_preferences.c?id=69f2f4a16f44ae7f6ab94f39623f2f44dfa0a754'>69f2f4a1 ^
e5ac12af ^
69f2f4a1 ^

a2726b6a ^

69f2f4a1 ^
a2726b6a ^
69f2f4a1 ^
2af418fd ^

e5ac12af ^
69f2f4a1 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39