fix: only count get requests as page loads

This commit is contained in:
Per Stark
2025-09-06 11:16:12 +02:00
parent e150b476c3
commit fdf29bb735

View File

@@ -1,5 +1,6 @@
use axum::{ use axum::{
extract::{Request, State}, extract::{Request, State},
http::Method,
middleware::Next, middleware::Next,
response::Response, response::Response,
}; };
@@ -19,7 +20,8 @@ where
S: ProvidesDb + Clone + Send + Sync + 'static, S: ProvidesDb + Clone + Send + Sync + 'static,
{ {
let path = request.uri().path(); let path = request.uri().path();
if !path.starts_with("/assets") && !path.contains('.') { // Only count visits/page loads for GET requests to non-asset, non-static paths
if request.method() == Method::GET && !path.starts_with("/assets") && !path.contains('.') {
if !session.get::<bool>("counted_visitor").unwrap_or(false) { if !session.get::<bool>("counted_visitor").unwrap_or(false) {
let _ = Analytics::increment_visitors(state.db()).await; let _ = Analytics::increment_visitors(state.db()).await;
session.set("counted_visitor", true); session.set("counted_visitor", true);