Explorar el Código

perf: limit rows to 1 for get_value and exists

version-14
Ankush Menat hace 3 años
padre
commit
b97cfed6d7
Se han modificado 1 ficheros con 20 adiciones y 15 borrados
  1. +20
    -15
      frappe/database/database.py

+ 20
- 15
frappe/database/database.py Ver fichero

@@ -384,7 +384,7 @@ class Database(object):
""" """


ret = self.get_values(doctype, filters, fieldname, ignore, as_dict, debug, ret = self.get_values(doctype, filters, fieldname, ignore, as_dict, debug,
order_by, cache=cache, for_update=for_update, run=run, pluck=pluck, distinct=distinct)
order_by, cache=cache, for_update=for_update, run=run, pluck=pluck, distinct=distinct, limit=1)


if not run: if not run:
return ret return ret
@@ -393,7 +393,7 @@ class Database(object):


def get_values(self, doctype, filters=None, fieldname="name", ignore=None, as_dict=False, def get_values(self, doctype, filters=None, fieldname="name", ignore=None, as_dict=False,
debug=False, order_by="KEEP_DEFAULT_ORDERING", update=None, cache=False, for_update=False, debug=False, order_by="KEEP_DEFAULT_ORDERING", update=None, cache=False, for_update=False,
run=True, pluck=False, distinct=False):
run=True, pluck=False, distinct=False, limit=None):
"""Returns multiple document properties. """Returns multiple document properties.


:param doctype: DocType name. :param doctype: DocType name.
@@ -423,14 +423,15 @@ class Database(object):


if isinstance(filters, list): if isinstance(filters, list):
out = self._get_value_for_many_names( out = self._get_value_for_many_names(
doctype,
filters,
fieldname,
order_by,
doctype=doctype,
names=filters,
field=fieldname,
order_by=order_by,
debug=debug, debug=debug,
run=run, run=run,
pluck=pluck, pluck=pluck,
distinct=distinct, distinct=distinct,
limit=limit,
) )


else: else:
@@ -444,17 +445,18 @@ class Database(object):
if order_by: if order_by:
order_by = "modified" if order_by == "KEEP_DEFAULT_ORDERING" else order_by order_by = "modified" if order_by == "KEEP_DEFAULT_ORDERING" else order_by
out = self._get_values_from_table( out = self._get_values_from_table(
fields,
filters,
doctype,
as_dict,
debug,
order_by,
update,
fields=fields,
filters=filters,
doctype=doctype,
as_dict=as_dict,
debug=debug,
order_by=order_by,
update=update,
for_update=for_update, for_update=for_update,
run=run, run=run,
pluck=pluck, pluck=pluck,
distinct=distinct
distinct=distinct,
limit=limit,
) )
except Exception as e: except Exception as e:
if ignore and (frappe.db.is_missing_column(e) or frappe.db.is_table_missing(e)): if ignore and (frappe.db.is_missing_column(e) or frappe.db.is_table_missing(e)):
@@ -623,6 +625,7 @@ class Database(object):
run=True, run=True,
pluck=False, pluck=False,
distinct=False, distinct=False,
limit=None,
): ):
field_objects = [] field_objects = []


@@ -641,6 +644,7 @@ class Database(object):
field_objects=field_objects, field_objects=field_objects,
fields=fields, fields=fields,
distinct=distinct, distinct=distinct,
limit=limit,
) )
if ( if (
fields == "*" fields == "*"
@@ -654,7 +658,7 @@ class Database(object):
) )
return r return r


def _get_value_for_many_names(self, doctype, names, field, order_by, debug=False, run=True, pluck=False, distinct=False):
def _get_value_for_many_names(self, doctype, names, field, order_by, debug=False, run=True, pluck=False, distinct=False, limit=None):
names = list(filter(None, names)) names = list(filter(None, names))
if names: if names:
return self.get_all( return self.get_all(
@@ -667,6 +671,7 @@ class Database(object):
as_list=1, as_list=1,
run=run, run=run,
distinct=distinct, distinct=distinct,
limit_page_length=limit
) )
else: else:
return {} return {}


Cargando…
Cancelar
Guardar