Skip to content

Commit 0849fb2

Browse files
committed
Add a small re-complexity mitigation
Signed-off-by: DL6ER <[email protected]>
1 parent 528e38b commit 0849fb2

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

app/labeldesigner/label.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ def datetime_replacer(match):
182182
else:
183183
now = datetime.datetime.now()
184184
return now.strftime(fmt)
185-
line['text'] = re.sub(r"\{\{datetime:([^}]+)\}\}", datetime_replacer, line['text'])
185+
# Performance issue mitigation
186+
if len(line['text']) < 100:
187+
line['text'] = re.sub(r"\{\{datetime:([^}]+)\}\}", datetime_replacer, line['text'])
186188

187189
# Replace {{uuid}} with a new UUID
188190
if "{{uuid}}" in line['text']:
@@ -196,7 +198,9 @@ def datetime_replacer(match):
196198
def env_replacer(match):
197199
var_name = match.group(1)
198200
return os.getenv(var_name, "")
199-
line['text'] = re.sub(r"\{\{env:([^}]+)\}\}", env_replacer, line['text'])
201+
# Performance issue mitigation
202+
if len(line['text']) < 100:
203+
line['text'] = re.sub(r"\{\{env:([^}]+)\}\}", env_replacer, line['text'])
200204

201205
# Increment counter
202206
self._counter += 1

0 commit comments

Comments
 (0)