UniversitaDellaCalabria / Portale-PoC

Apache License 2.0
1 stars 0 forks source link

Publication and Page Hit Counter #14

Open peppelinux opened 4 years ago

peppelinux commented 4 years ago

There would be the need of a hit counter. Something already exists, like django-hitcount: https://django-hitcount.readthedocs.io/en/latest/overview.html

I think that a django-hitcount should not be used because of the real possibility to cache the pages (for huge loads). I'd like instead to implement a custom hitcount js based. Each time a user open a content (page or publication) a js in it will:

if the current uri path doesn't exists:

The API resource would be accessibile with something like api/hitcounter/<app_label:str>/<model:str>/<pk:int> Backed side a memcached/redis storage would be adopted with a key:value lifetime of N seconds. Each time a hitcount will be triggered API side, the backed would check if another sessionid: uri have been stored in the local memcached/redis, if not -> counter +1

this would limit possibile resource abuses

peppelinux commented 4 years ago

The lock manager would be implemented in Redis

https://github.com/jazzband/django-redis#locks

peppelinux commented 3 years ago
    # hit counter on page
    r_head = dict(request.headers.items())
    srcip = r_head.get("X-Forwarded-For") or \
            r_head.get("X-Real-Ip", request.META['REMOTE_ADDR'])

but also see sessionid

...