8000 perf: defer imports during CLI (backport #24945) by mergify[bot] · Pull Request #24946 · frappe/frappe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

perf: defer imports during CLI (backport #24945) #24946

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

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
J 8000 ump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frappe/commands/redis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import click

import frappe
from frappe.utils.redis_queue import RedisQueue


@click.command("create-rq-users")
Expand All @@ -21,6 +20,7 @@ def create_rq_users(set_admin_password=False, use_rq_auth=False):
and app config is used by app while connecting to redis server.
"""
from frappe.installer import update_site_config
from frappe.utils.redis_queue import RedisQueue

acl_file_path = os.path.abspath("../config/redis_queue.acl")

Expand Down
3 changes: 2 additions & 1 deletion frappe/core/doctype/file/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from urllib.parse import quote, unquote

from PIL import Image, ImageFile, ImageOps
from requests.exceptions import HTTPError, SSLError

import frappe
from frappe import _
Expand Down Expand Up @@ -427,6 +426,8 @@ def make_thumbnail(
suffix: str = "small",
crop: bool = False,
) -> str:
from requests.exceptions import HTTPError, SSLError

if not self.file_url:
return

Expand Down
10 changes: 6 additions & 4 deletions frappe/core/doctype/file/utils.py
BCC0
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from urllib.parse import unquote

import filetype
import requests
import requests.exceptions
from PIL import Image

import frappe
from frappe import _, safe_decode
Expand Down Expand Up @@ -86,6 +83,8 @@ def get_extension(


def get_local_image(file_url: str) -> tuple["ImageFile", str, str]:
from PIL import Image

if file_url.startswith("/private"):
file_url_path = (file_url.lstrip("/"),)
else:
Expand Down Expand Up @@ -116,7 +115,10 @@ def get_local_image(file_url: str) -> tuple["ImageFile", str, str]:


def get_web_image(file_url: str) -> tuple["ImageFile", str, str]:
# download
import requests
import requests.exceptions
from PIL import Image

file_url = frappe.utils.get_url(file_url)
r = requests.get(file_url, stream=True)
try:
Expand Down
4 changes: 1 addition & 3 deletions frappe/query_builder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@ def execute_child_queries(queries, result):
def prepare_query(query):
import inspect

from frappe.utils.safe_exec import SERVER_SCRIPT_FILE_PREFIX

param_collector = NamedParameterWrapper()
query = query.get_sql(param_wrapper=param_collector)
if frappe.flags.in_safe_exec:
from frappe.utils.safe_exec import check_safe_sql_query
from frappe.utils.safe_exec import SERVER_SCRIPT_FILE_PREFIX, check_safe_sql_query

if not check_safe_sql_query(query, throw=False):
callstack = inspect.stack()
Expand Down
0