diff --git a/relay/main.go b/relay/main.go index 4a934da..f8bab52 100644 --- a/relay/main.go +++ b/relay/main.go @@ -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() {

Welcome to LUMINA Relay!

Number of events stored: %d

View Event Stats

+

View Trending History

@@ -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)