Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking user codes is slow #1070

Open
2 tasks done
therealmrfox opened this issue Nov 27, 2024 · 0 comments
Open
2 tasks done

Checking user codes is slow #1070

therealmrfox opened this issue Nov 27, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@therealmrfox
Copy link

Checklist

  • I am using the latest version of Alarmo (latest version can be found here)
  • I checked for similar existing requests (both open and closed) before posting.

Alarmo Version

v1.10.7

HA Version

2024.11.3

Bug description

Calls to alarmo.disarm can take several seconds if there are multiple codes/users defined. I'm seeing ~6s for 13 users/codes.

How long it takes depends on which user's code is being checked.

I suspect this is because this code checks users in sequence. If the supplied code belongs to a user that's far down in the list (depending on order in which they were added?), a lot of bcrypt.checkpw() iterations are performed sequentially, which can be slow especially if running on an RPi.

Perhaps something like this could work?

def async_authenticate_user(self, code: str, user_id: str = None):
  users = ...
  def check_pw(user):
    if not user[const.ATTR_ENABLED]:
      continue
    elif not user[ATTR_CODE] and not code:
      return user
    if bcrypt.checkpw(code.encode("utf-8"), base64.b64decode(user[ATTR_CODE]):
      return user 

  with multiprocessing.Pool() as p:
    for user in p.imap(check_pw, users.itervalues()):
      if user: return user

  return

Similar report

Steps to reproduce

  • add a generous amount of users, each with their unique code, to alarmo (~20 should do)
  • call disarm with the code of the last user added

Relevant log output

No response

@therealmrfox therealmrfox added the bug Something isn't working label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant