From e553ee166bef44dd675c8c4481436d7181963499 Mon Sep 17 00:00:00 2001
From: dusk
Date: Thu, 16 Jan 2025 15:55:07 +0300
Subject: [PATCH] fix: dont use reduce
---
src/routes/+layout.server.ts | 9 ++++++++-
src/routes/+layout.svelte | 6 +-----
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts
index 3cf7766..ebb0025 100644
--- a/src/routes/+layout.server.ts
+++ b/src/routes/+layout.server.ts
@@ -15,9 +15,16 @@ export async function load({ request, cookies, url }) {
throw error(403, "get a better user agent silly")
}
+ const lastVisitors = addLastVisitor(request, cookies)
+ let recentVisitCount = 0
+ for (const [_, visitor] of lastVisitors) {
+ recentVisitCount += visitor.visits.length
+ }
+
return {
route: url.pathname,
visitCount: incrementVisitCount(request, cookies),
- lastVisitors: addLastVisitor(request, cookies),
+ lastVisitors,
+ recentVisitCount,
}
}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 848156b..fc68000 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -42,10 +42,6 @@
$: title = getTitle(data.route);
- $: recentVisitCount = data.lastVisitors.values().reduce(
- (total, visitor) => { return total + visitor.visits.length; }, 0
- )
-
const svgSquiggles = [[2], [3], [2], [3], [1]];
@@ -175,7 +171,7 @@
uniq recent visits = {data.lastVisitors.size.toString().padStart(3, ".")}
- {recentVisitCount} recent clicks
+ {data.recentVisitCount} recent clicks
{#if isRoute("entries") || isRoute("log")}