* Fix error when users table does not exist
In multitenant context, when schema is switched to and the tables are
not created yet, getting `User.current` will fail with
ActiveRecord::StatementInvalid:"PG::UndefinedTable: ERROR: relation \"users\" does not exist" [...]
To prevent it, check if the table exists first and return `nil` if not.
* Avoid logging "slow sql" for database creation
* Better performance for handling unexisting users table
Checking multiple times the users table existence when something is
logged is probably a bad idea. Better rescue errors.
Also cache the return value of `#current_user` to call the method only
once.
We can use the activerecord.sql notification hook to determine slow
running queries without needing to look into the psql slow log.
The default threshold is set to 2000ms for now, can be changed freely with
`OPENPROJECT_SQL__SLOW__QUERY__THRESHOLD=X` where X is an integer
threshold in miliseconds