chore: inline unnecessary indirection (#28250)
This commit is contained in:
parent
947054e7e6
commit
86f70b9e98
2 changed files with 44 additions and 101 deletions
|
|
@ -603,48 +603,43 @@ class Database:
|
|||
order_by = None
|
||||
|
||||
if isinstance(filters, list):
|
||||
out = self._get_value_for_many_names(
|
||||
doctype=doctype,
|
||||
names=filters,
|
||||
field=fieldname,
|
||||
order_by=order_by,
|
||||
debug=debug,
|
||||
run=run,
|
||||
pluck=pluck,
|
||||
distinct=distinct,
|
||||
limit=limit,
|
||||
as_dict=as_dict,
|
||||
skip_locked=skip_locked,
|
||||
wait=True,
|
||||
for_update=for_update,
|
||||
)
|
||||
|
||||
if filters := list(f for f in filters if f is not None):
|
||||
out = frappe.qb.get_query(
|
||||
table=doctype,
|
||||
fields=fieldname,
|
||||
filters=filters,
|
||||
order_by=order_by,
|
||||
distinct=distinct,
|
||||
limit=limit,
|
||||
validate_filters=True,
|
||||
for_update=for_update,
|
||||
skip_locked=skip_locked,
|
||||
wait=True,
|
||||
).run(debug=debug, run=run, as_dict=as_dict, pluck=pluck)
|
||||
else:
|
||||
out = {}
|
||||
else:
|
||||
fields = fieldname
|
||||
if fieldname != "*":
|
||||
if isinstance(fieldname, str):
|
||||
fields = [fieldname]
|
||||
|
||||
if (filters is not None) and (filters != doctype or doctype == "DocType"):
|
||||
try:
|
||||
if order_by:
|
||||
order_by = "creation" if order_by == DefaultOrderBy else order_by
|
||||
out = self._get_values_from_table(
|
||||
fields=fields,
|
||||
|
||||
query = frappe.qb.get_query(
|
||||
table=doctype,
|
||||
filters=filters,
|
||||
doctype=doctype,
|
||||
as_dict=as_dict,
|
||||
debug=debug,
|
||||
order_by=order_by,
|
||||
update=update,
|
||||
run=run,
|
||||
pluck=pluck,
|
||||
distinct=distinct,
|
||||
limit=limit,
|
||||
for_update=for_update,
|
||||
skip_locked=skip_locked,
|
||||
wait=wait,
|
||||
fields=fieldname,
|
||||
distinct=distinct,
|
||||
limit=limit,
|
||||
validate_filters=True,
|
||||
)
|
||||
if isinstance(fieldname, str) and fieldname == "*":
|
||||
as_dict = True
|
||||
out = query.run(as_dict=as_dict, debug=debug, update=update, run=run, pluck=pluck)
|
||||
|
||||
except Exception as e:
|
||||
if ignore and (
|
||||
frappe.db.is_missing_column(e)
|
||||
|
|
@ -655,14 +650,29 @@ class Database:
|
|||
elif (not ignore) and frappe.db.is_table_missing(e):
|
||||
# table not found, look in singles
|
||||
out = self.get_values_from_single(
|
||||
fields, filters, doctype, as_dict, debug, update, run=run, distinct=distinct
|
||||
"*" if fieldname == "*" else [fieldname],
|
||||
filters,
|
||||
doctype,
|
||||
as_dict,
|
||||
debug,
|
||||
update,
|
||||
run=run,
|
||||
distinct=distinct,
|
||||
)
|
||||
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
out = self.get_values_from_single(
|
||||
fields, filters, doctype, as_dict, debug, update, run=run, pluck=pluck, distinct=distinct
|
||||
"*" if fieldname == "*" else [fieldname],
|
||||
filters,
|
||||
doctype,
|
||||
as_dict,
|
||||
debug,
|
||||
update,
|
||||
run=run,
|
||||
pluck=pluck,
|
||||
distinct=distinct,
|
||||
)
|
||||
|
||||
if cache and cache_key:
|
||||
|
|
@ -869,73 +879,6 @@ class Database:
|
|||
"""Alias for get_single_value"""
|
||||
return self.get_single_value(*args, **kwargs)
|
||||
|
||||
def _get_values_from_table(
|
||||
self,
|
||||
fields,
|
||||
filters,
|
||||
doctype,
|
||||
as_dict,
|
||||
*,
|
||||
debug=False,
|
||||
order_by=None,
|
||||
update=None,
|
||||
for_update=False,
|
||||
skip_locked=False,
|
||||
wait=True,
|
||||
run=True,
|
||||
pluck=False,
|
||||
distinct=False,
|
||||
limit=None,
|
||||
):
|
||||
query = frappe.qb.get_query(
|
||||
table=doctype,
|
||||
filters=filters,
|
||||
order_by=order_by,
|
||||
for_update=for_update,
|
||||
skip_locked=skip_locked,
|
||||
wait=wait,
|
||||
fields=fields,
|
||||
distinct=distinct,
|
||||
limit=limit,
|
||||
validate_filters=True,
|
||||
)
|
||||
if isinstance(fields, str) and fields == "*":
|
||||
as_dict = True
|
||||
|
||||
return query.run(as_dict=as_dict, debug=debug, update=update, run=run, pluck=pluck)
|
||||
|
||||
def _get_value_for_many_names(
|
||||
self,
|
||||
doctype,
|
||||
names,
|
||||
field,
|
||||
order_by,
|
||||
*,
|
||||
debug=False,
|
||||
run=True,
|
||||
pluck=False,
|
||||
distinct=False,
|
||||
limit=None,
|
||||
as_dict=False,
|
||||
for_update=False,
|
||||
skip_locked=False,
|
||||
wait=True,
|
||||
):
|
||||
if names := list(filter(None, names)):
|
||||
return frappe.qb.get_query(
|
||||
doctype,
|
||||
fields=field,
|
||||
filters=names,
|
||||
order_by=order_by,
|
||||
distinct=distinct,
|
||||
limit=limit,
|
||||
validate_filters=True,
|
||||
for_update=for_update,
|
||||
skip_locked=skip_locked,
|
||||
wait=wait,
|
||||
).run(debug=debug, run=run, as_dict=as_dict, pluck=pluck)
|
||||
return {}
|
||||
|
||||
def set_value(
|
||||
self,
|
||||
dt: str,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Engine:
|
|||
def get_query(
|
||||
self,
|
||||
table: str | Table,
|
||||
fields: list | tuple | None = None,
|
||||
fields: str | list | tuple | None = None,
|
||||
filters: dict[str, FilterValue] | FilterValue | list[list | FilterValue] | None = None,
|
||||
order_by: str | None = None,
|
||||
group_by: str | None = None,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue