Skip to content

Commit

Permalink
Geo coding: Use always-ascii cache keys
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Jan 8, 2024
1 parent 8185175 commit 0f44702
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/pretix/control/views/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
# <https://www.gnu.org/licenses/>.
#
import hashlib
import logging
from urllib.parse import quote

Expand All @@ -36,7 +37,8 @@
class GeoCodeView(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs):
q = self.request.GET.get('q')
cd = cache.get('geocode:{}'.format(q))
cache_key = 'geocode:{}'.format(hashlib.sha256(q.encode()).hexdigest())
cd = cache.get(cache_key)
if cd:
return JsonResponse({
'success': True,
Expand All @@ -61,7 +63,7 @@ def get(self, request, *args, **kwargs):
'results': []
}, status=200)

cache.set('geocode:{}'.format(q), res, timeout=3600 * 6)
cache.set(cache_key, res, timeout=3600 * 6)
return JsonResponse({
'success': True,
'results': res
Expand Down

0 comments on commit 0f44702

Please sign in to comment.