Skip to content

Commit e1b83a2

Browse files
committed
Translation call counter +1 only when not hitting cache
1 parent 302c86a commit e1b83a2

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lang/translation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ def translate_text(self, text, dest_language, source_language=None):
106106
return self._fake_translation(text, dest_language, source_language)
107107

108108
global IFRC_TRANSLATION_CALL_COUNT
109-
with IFRC_TRANSLATION_CALL_LOCK:
110-
IFRC_TRANSLATION_CALL_COUNT += 1
111-
logger.info(f"IFRC translation API call count: {IFRC_TRANSLATION_CALL_COUNT}")
112109

113110
# A dirty workaround to handle oversized HTML+CSS texts, usually tables:
114111
textTail = ""
@@ -146,9 +143,12 @@ def translate_text(self, text, dest_language, source_language=None):
146143
dest_language=dest_language,
147144
).first()
148145
if cache:
149-
logger.info(f"translation cache hit: {text[:30]}... {source_language}>{dest_language}")
146+
logger.info(f"IFRC translation cache hit: {text[:30]}... {source_language}>{dest_language}")
150147
return cache.translated_text
151148

149+
with IFRC_TRANSLATION_CALL_LOCK:
150+
IFRC_TRANSLATION_CALL_COUNT += 1
151+
logger.info(f"IFRC translation API call count: {IFRC_TRANSLATION_CALL_COUNT}")
152152
logger.info(f"IFRC translation API call: {text[:30]}... {source_language}>{dest_language}")
153153
response = requests.post(
154154
self.url,

registrations/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def is_valid_domain(email):
1818
.exists()
1919
)
2020

21-
if is_allowed or domain in ["ifrc.org", "arcs.org.af", "voroskereszt.hu"]:
21+
if is_allowed or domain in ["voroskereszt.hu"]: # This array check is only for testing
2222
return True
2323
return False
2424

0 commit comments

Comments
 (0)