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 1f2c833
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions hitcount/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import re

from django.apps import apps
try:
from django.utils.regex_helper import _lazy_re_compile
except ImportError:
from django.core.validators 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 1f2c833

Please sign in to comment.