aboutsummaryrefslogtreecommitdiff
blob: 7918b787030837807f018dfe5036743f9d76af4c (plain)
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
40
41
42
43
44
45
package cache

import (
	"archives/pkg/app/home"
	"archives/pkg/app/list"
	"archives/pkg/app/popular"
	"archives/pkg/cache"
	"archives/pkg/config"
	"fmt"
	"net/http"
	"time"
)

func UpdateHandler(w http.ResponseWriter, r *http.Request) {
	Update()
	w.Write([]byte("Updated."))
}

func Init(){
	cache.Init()
}

func Update(){
	fmt.Println("Updating caches...")

	startTime := time.Now()
	cache.Put("/", home.ComputeTemplateData())
	fmt.Println("> Updated '/' in " + time.Now().Sub(startTime).String())

	startTime = time.Now()
	cache.Put("/lists", list.ComputeBrowseTemplateData())
	fmt.Println("> Updated '/lists' in " + time.Now().Sub(startTime).String())

	startTime = time.Now()
	cache.Put("/popular", popular.ComputeThreadsTemplateData())
	fmt.Println("> Updated '/popular' in " + time.Now().Sub(startTime).String())

	startTime = time.Now()
	for _, listName := range config.AllPublicMailingLists() {
		tmpStartTime := time.Now()
		cache.Put("/"+listName+"/", list.ComputeShowTemplateData(listName))
		fmt.Println(">> Updated '/" + listName + "/' in " + time.Now().Sub(tmpStartTime).String())
	}
	fmt.Println("> Updated '/{{list}}/' in " + time.Now().Sub(startTime).String())
}