File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33import re
44import base64
55import logging
6+ import concurrent .futures
67
78import bcrypt
89from homeassistant .core import (
4849
4950_LOGGER = logging .getLogger (__name__ )
5051
52+ # Max number of threads to start when checking user codes.
53+ MAX_WORKERS = 4
5154# Number of rounds of hashing when computing user hashes.
5255BCRYPT_NUM_ROUNDS = 10
5356
@@ -369,11 +372,17 @@ def check_user_code(user, code):
369372 return check_user_code (self .store .async_get_user (user_id ), code )
370373
371374 users = self .store .async_get_users ()
372- for user in users .values ():
373- result = check_user_code (user , code )
374- if result :
375- return result
376- return None
375+ with concurrent .futures .ThreadPoolExecutor (
376+ max_workers = MAX_WORKERS
377+ ) as executor :
378+ futures = [
379+ executor .submit (check_user_code , user , code )
380+ for user in users .values ()
381+ ]
382+ for future in concurrent .futures .as_completed (futures ):
383+ if future .result ():
384+ executor .shutdown (wait = False , cancel_futures = True )
385+ return future .result ()
377386
378387 return await self .hass .async_add_executor_job (_authenticate_user_sync )
379388
You can’t perform that action at this time.
0 commit comments