considering lazy loading for non-critical loc

This commit is contained in:
doanguyen 2019-12-22 00:18:16 +01:00 committed by Son Nguyen Kim
parent de0368c20f
commit 1393b80970
4 changed files with 9 additions and 8 deletions

View File

@ -3,7 +3,7 @@ import subprocess
from dotenv import load_dotenv
SHA1 = subprocess.getoutput("git rev-parse HEAD")
SHA1 = lambda: subprocess.getoutput("git rev-parse HEAD")
ROOT_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))

View File

@ -104,7 +104,7 @@ class User(db.Model, ModelMixin, UserMixin):
@classmethod
def create(cls, email, name, password=None, **kwargs):
user: User = super(User, cls).create(email=email, name=name, **kwargs)
user = super(User, cls).create(email=email, name=name, **kwargs)
if not password:
# set a random password

View File

@ -4,7 +4,7 @@ from app.monitor.base import monitor_bp
@monitor_bp.route("/git")
def git_sha1():
return SHA1
return SHA1()
@monitor_bp.route("/exception")

View File

@ -7,19 +7,20 @@ from unidecode import unidecode
from .config import WORDS_FILE_PATH
from .log import LOG
with open(WORDS_FILE_PATH) as f:
LOG.d("load words file: %s", WORDS_FILE_PATH)
_words = f.read().split()
def _word():
with open(WORDS_FILE_PATH) as f:
LOG.d("load words file: %s", WORDS_FILE_PATH)
return f.read().split()
def random_word():
return random.choice(_words)
return random.choice(_word())
def random_words():
"""Generate a random words. Used to generate user-facing string, for ex email addresses"""
nb_words = random.randint(2, 3)
return "_".join([random.choice(_words) for i in range(nb_words)])
return "_".join([random.choice(_word()) for _ in range(nb_words)])
def random_string(length=10):