perf: Login Page
Improves performance 3x - from 0.047s to 0.017s * Use frappe.get_*_settings to query table once * Use cached LDAP Settings' document via get_ldap_client_settings * Use single get_all to query all Social Login providers and related data * Skip provider if client_secret doesn't exist
This commit is contained in:
parent
a1691784a8
commit
7e25cc4568
2 changed files with 26 additions and 31 deletions
|
|
@ -120,7 +120,7 @@ class LDAPSettings(Document):
|
|||
def get_ldap_client_settings():
|
||||
# return the settings to be used on the client side.
|
||||
result = {"enabled": False}
|
||||
ldap = frappe.get_doc("LDAP Settings")
|
||||
ldap = frappe.get_cached_doc("LDAP Settings")
|
||||
if ldap.enabled:
|
||||
result["enabled"] = True
|
||||
result["method"] = "frappe.integrations.doctype.ldap_settings.ldap_settings.login"
|
||||
|
|
|
|||
|
|
@ -36,22 +36,14 @@ def get_context(context):
|
|||
frappe.local.flags.redirect_location = redirect_to
|
||||
raise frappe.Redirect
|
||||
|
||||
# get settings from site config
|
||||
context.no_header = True
|
||||
context.for_test = "login.html"
|
||||
context["title"] = "Login"
|
||||
context["provider_logins"] = []
|
||||
context["disable_signup"] = frappe.utils.cint(
|
||||
frappe.db.get_single_value("Website Settings", "disable_signup")
|
||||
)
|
||||
context["logo"] = (
|
||||
frappe.db.get_single_value("Website Settings", "app_logo")
|
||||
or frappe.get_hooks("app_logo_url")[-1]
|
||||
)
|
||||
context["disable_signup"] = frappe.utils.cint(frappe.get_website_settings("disable_signup"))
|
||||
context["logo"] = frappe.get_website_settings("app_logo") or frappe.get_hooks("app_logo_url")[-1]
|
||||
context["app_name"] = (
|
||||
frappe.db.get_single_value("Website Settings", "app_name")
|
||||
or frappe.get_system_settings("app_name")
|
||||
or _("Frappe")
|
||||
frappe.get_website_settings("app_name") or frappe.get_system_settings("app_name") or _("Frappe")
|
||||
)
|
||||
|
||||
signup_form_template = frappe.get_hooks("signup_form_template")
|
||||
|
|
@ -61,38 +53,41 @@ def get_context(context):
|
|||
path = frappe.get_attr(signup_form_template[-1])()
|
||||
else:
|
||||
path = "frappe/templates/signup.html"
|
||||
|
||||
if path:
|
||||
context["signup_form_template"] = frappe.get_template(path).render()
|
||||
|
||||
providers = [
|
||||
i.name
|
||||
for i in frappe.get_all("Social Login Key", filters={"enable_social_login": 1}, order_by="name")
|
||||
]
|
||||
providers = frappe.get_all(
|
||||
"Social Login Key",
|
||||
filters={"enable_social_login": 1},
|
||||
fields=["name", "client_id", "base_url", "provider_name", "icon"],
|
||||
order_by="name",
|
||||
)
|
||||
|
||||
for provider in providers:
|
||||
client_id, base_url = frappe.get_value("Social Login Key", provider, ["client_id", "base_url"])
|
||||
client_secret = get_decrypted_password("Social Login Key", provider, "client_secret")
|
||||
provider_name = frappe.get_value("Social Login Key", provider, "provider_name")
|
||||
client_secret = get_decrypted_password("Social Login Key", provider.name, "client_secret")
|
||||
if not client_secret:
|
||||
continue
|
||||
|
||||
icon = None
|
||||
icon_url = frappe.get_value("Social Login Key", provider, "icon")
|
||||
if icon_url:
|
||||
if provider_name != "Custom":
|
||||
icon = "<img src='{0}' alt={1}>".format(icon_url, provider_name)
|
||||
if provider.icon:
|
||||
if provider.provider_name == "Custom":
|
||||
icon = get_icon_html(provider.icon, small=True)
|
||||
else:
|
||||
icon = get_icon_html(icon_url, small=True)
|
||||
icon = f"<img src='{provider.icon}' alt={provider.provider_name}>"
|
||||
|
||||
if get_oauth_keys(provider) and client_secret and client_id and base_url:
|
||||
if provider.client_id and provider.base_url and get_oauth_keys(provider.name):
|
||||
context.provider_logins.append(
|
||||
{
|
||||
"name": provider,
|
||||
"provider_name": provider_name,
|
||||
"auth_url": get_oauth2_authorize_url(provider, redirect_to),
|
||||
"name": provider.name,
|
||||
"provider_name": provider.provider_name,
|
||||
"auth_url": get_oauth2_authorize_url(provider.name, redirect_to),
|
||||
"icon": icon,
|
||||
}
|
||||
)
|
||||
context["social_login"] = True
|
||||
ldap_settings = LDAPSettings.get_ldap_client_settings()
|
||||
context["ldap_settings"] = ldap_settings
|
||||
|
||||
context["ldap_settings"] = LDAPSettings.get_ldap_client_settings()
|
||||
|
||||
login_label = [_("Email")]
|
||||
|
||||
|
|
@ -102,7 +97,7 @@ def get_context(context):
|
|||
if frappe.utils.cint(frappe.get_system_settings("allow_login_using_user_name")):
|
||||
login_label.append(_("Username"))
|
||||
|
||||
context["login_label"] = " {0} ".format(_("or")).join(login_label)
|
||||
context["login_label"] = f" {_('or')} ".join(login_label)
|
||||
|
||||
return context
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue