Make the visitor counter increment when a new session is created

This commit is contained in:
swag 2022-04-03 21:34:22 -04:00
parent 3532310738
commit 27ec34b208
2 changed files with 8 additions and 2 deletions

View File

@ -40,7 +40,13 @@ under sub ($c) {
# https://paramdeo.com/blog/opting-your-website-out-of-googles-floc-network # https://paramdeo.com/blog/opting-your-website-out-of-googles-floc-network
$c->res->headers->header('Permissions-Policy', 'interest-cohort=()'); $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'); $c->stash(status => 403) if $c->flash('error');

View File

@ -19,7 +19,7 @@ sub get_visitor_count($self) {
} }
sub increment_visitor_count($self) { sub increment_visitor_count($self) {
$self->pg->db->query(<<~'END_SQL')->text() $self->pg->db->query(<<~'END_SQL')
UPDATE counters UPDATE counters
SET counter_value = counter_value + 1 SET counter_value = counter_value + 1
WHERE counter_name = 'visitor'; WHERE counter_name = 'visitor';