add trending history link to startpage
This commit is contained in:
parent
94439ee30b
commit
a5d6cc7e2e
@ -17,6 +17,7 @@ import (
|
||||
|
||||
// Cache for storing generic data like event counts
|
||||
var dataCache = cache.New()
|
||||
|
||||
const eventCountCacheKey = "total_event_count"
|
||||
const eventCountCacheDuration = 1 * time.Minute
|
||||
|
||||
@ -40,7 +41,7 @@ func getTotalEventCount(db *postgresql.PostgresBackend) (int, error) {
|
||||
if err := row.Scan(&count); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
|
||||
// Update the cache
|
||||
dataCache.Set(eventCountCacheKey, count, eventCountCacheDuration)
|
||||
return count, nil
|
||||
@ -124,7 +125,7 @@ func main() {
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("content-type", "text/html")
|
||||
|
||||
// Get event count from cache
|
||||
// Get event count from cache
|
||||
count, err := getTotalEventCount(&db)
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting event count: %v\n", err)
|
||||
@ -178,6 +179,7 @@ func main() {
|
||||
<h1>Welcome to LUMINA Relay!</h1>
|
||||
<p>Number of events stored: %d</p>
|
||||
<p><a href="/stats">View Event Stats</a></p>
|
||||
<p><a href="/trending/history">View Trending History</a></p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -276,7 +278,7 @@ func main() {
|
||||
mux.HandleFunc("/api/stats", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
// Get total count from cache
|
||||
// Get total count from cache
|
||||
totalCount, err := getTotalEventCount(&db)
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("Error getting event count: %v", err), http.StatusInternalServerError)
|
||||
|
Loading…
x
Reference in New Issue
Block a user