Skip to content

Commit

Permalink
perf: ⚡️ Prevent compiling of regex for IP on every import
Browse files Browse the repository at this point in the history
  • Loading branch information
abhiabhi94 committed Jul 7, 2021
1 parent 250c717 commit 416f872
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions hitcount/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def _setup(self):
self._wrapped = Settings(app_settings, django_settings)


DEPRECATED_SETTINGS = {
_DEPRECATED_SETTINGS_DJANGO = {
'USE_TZ' if django.VERSION > (4, 0) else None,
'PASSWORD_RESET_TIMEOUT_DAYS' if django.VERSION > (3, 0) else None,
'DEFAULT_CONTENT_TYPE' if django.VERSION > (2, 2) else None,
Expand All @@ -24,7 +24,7 @@ def __init__(self, *args):
setattr(self, attr, getattr(item, attr))
for item in args
for attr in dir(item)
if attr == attr.upper() and attr.upper() not in DEPRECATED_SETTINGS
if attr == attr.upper() and attr.upper() not in _DEPRECATED_SETTINGS_DJANGO
]


Expand Down
5 changes: 2 additions & 3 deletions hitcount/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import re

from django.apps import apps
from django.utils.regex_helper import _lazy_re_compile

from hitcount.conf import settings

# this is not intended to be an all-knowing IP address regex
IP_RE = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')
IP_RE = _lazy_re_compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')


def get_ip(request):
Expand Down

0 comments on commit 416f872

Please sign in to comment.