From 27ec34b20828105ab8a066a8f489acca630db40e Mon Sep 17 00:00:00 2001 From: swag Date: Sun, 3 Apr 2022 21:34:22 -0400 Subject: [PATCH] Make the visitor counter increment when a new session is created --- guestbook-ng.pl | 8 +++++++- lib/GuestbookNg/Model/Counter.pm | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/guestbook-ng.pl b/guestbook-ng.pl index 1d0be1e..3235cbb 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -40,7 +40,13 @@ under sub ($c) { # https://paramdeo.com/blog/opting-your-website-out-of-googles-floc-network $c->res->headers->header('Permissions-Policy', 'interest-cohort=()'); - $c->session(expiration => 86400); + unless ($c->session('counted')) { + $c->counter->increment_visitor_count(); + $c->session( + expiration => 86400, + counted => 'true' + ); + } $c->stash(status => 403) if $c->flash('error'); diff --git a/lib/GuestbookNg/Model/Counter.pm b/lib/GuestbookNg/Model/Counter.pm index 88ce701..e99b751 100644 --- a/lib/GuestbookNg/Model/Counter.pm +++ b/lib/GuestbookNg/Model/Counter.pm @@ -19,7 +19,7 @@ sub get_visitor_count($self) { } sub increment_visitor_count($self) { - $self->pg->db->query(<<~'END_SQL')->text() + $self->pg->db->query(<<~'END_SQL') UPDATE counters SET counter_value = counter_value + 1 WHERE counter_name = 'visitor';