Cache user retrieval
The user_id is stored in the flask session. On every page load, we query the database to get: - the user objet (user_account table) - the user's groups (group table) to know what the user can access If we try to cache the user_load function, the following error is raised when retrieving the groups: sqlalchemy.orm.exc.DetachedInstanceError: Parent instance <User at 0x7f51e050a940> is not bound to a Session; lazy load operation of attribute 'grp' cannot proceed The groups from AD are only stored to map them with CSENTRY_LDAP_GROUPS. We don't do any query on them (get all users from one group). As we always query them with one user, it's more efficient to store them in the user_account table as an array than in a separate table. This allows to easily cache the load_user function. Note that we have to remember to add the current_user to the sqlalchemy session if we want to modify it or access a relationship (like tokens)! The load_user function is now cached for 30 minutes. This decreases a lot the number of database queries. Fix INFRA-156
Please register or sign in to comment