Skip to content

Commit c60cc1b

Browse files
committed
Construct Faker objects used for person name generation only once. Results in a roughly 20% speedup of the test-suite. Commit ready for merge.
- Legacy-Id: 18020
1 parent 64de3fc commit c60cc1b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

ietf/person/factories.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import random
1010
import shutil
1111

12+
from functools import lru_cache
1213
from unidecode import unidecode
1314

1415
from django.conf import settings
@@ -24,14 +25,18 @@
2425

2526
fake = faker.Factory.create()
2627

27-
def random_faker():
28+
@lru_cache(maxsize=1)
29+
def acceptable_fakers():
2830
# The transliteration of some arabic and devanagari names introduces
2931
# non-alphabetic characgters that don't work with the draft author
3032
# extraction code, and also don't seem to match the way people with arabic
3133
# names romanize arabic names. Exlude those locales from name generation
3234
# in order to avoid test failures.
3335
locales = set( [ l for l in faker.config.AVAILABLE_LOCALES if not (l.startswith('ar_') or l.startswith('sg_')) ] )
34-
return faker.Faker(random.sample(locales, 1)[0])
36+
return [faker.Faker(locale) for locale in locales]
37+
38+
def random_faker():
39+
return random.sample(acceptable_fakers(), 1)[0]
3540

3641
class UserFactory(factory.DjangoModelFactory):
3742
class Meta:

0 commit comments

Comments
 (0)