aboutsummaryrefslogtreecommitdiff
path: root/dashboard.go
blob: ad3c565ceaa8fddebac7dc0ac17f12b3be1f5dab (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
package main

import (
	"fagott.pw/grilist/grilist"
	"github.com/julienschmidt/httprouter"
	"log"
	"net/http"
	"sync"
	"time"
)

func viewDashboard(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	user, _ := app.Charakterin.GetUserFromRequest(r)

	var categories []grilist.DashboardCategory

	t1 := time.Now()
	var wg sync.WaitGroup
	for _, module := range app.Modules {
		wg.Add(1)
		go func(module grilist.Module) {
			t2 := time.Now()
			for _, category := range module.ProvideDashboardData(user) {
				if len(category.Cards) > 0 {
					categories = append(categories, category)
				}
			}
			log.Printf("%s dashboard_data: %dms", module.Name(), time.Since(t2).Nanoseconds()/1000000)
			wg.Done()
		}(module)
	}
	wg.Wait()

	log.Printf("dashboard_data: %dms", time.Since(t1).Nanoseconds()/1000000)

	data := make(map[string]interface{})
	data["categories"] = categories
	data["user"] = user
	app.Renderer.RenderPage("dashboard", w, data)
}