gae-init/gae-init-babel — pull request #36 by mdxs (2014-03-18 10:18:44+00:00)
Title: Reducing get_locale overhead

Found that `auth/get_locale` was called 3 times on each request in `gae-init-babel`; and thus looked into the reasons why.

Adding a `traceback.print_stack(limit=5)` inside it showed that `auth/request_started` (associated with `@flask.request_started.connect_via(app)`) was calling it twice (easy to resolve... using local variable).

While the other call was due to `@babel.localeselector` being associated with `get_locale`; which seems to be okay (whatever makes Flask-Babel happy...) but clearly hinted at an opportunity to reduce overhead even more. Especially since the trace showed that the `@babel.localeselector` bound call (always?) follows the `@flask.request_started` call; which is why there now is a try-except to return first call result (if any).

This PR should thus improve efficiency, by eliminating one call and optimizing the typical flow of the two remaining calls trying to get the same thing in order (and not messing with that Flask and Flask-Babel stuff; assuming they are right to do so).