Commit dd995779 authored by Cédric Krier's avatar Cédric Krier
Browse files

Rename ModelStorage.count into ModelStorage.estimated_count

count is too common name for a standard method like #12016 reveals.
parent d1475c50226f
Pipeline #61573 passed with stages
in 23 minutes and 47 seconds
* Rename ModelStorage.count into ModelStorage.estimated_count
* Add border type to images
* Lock table on transaction start
* Use EXISTS for search on O2M with many records
......
......@@ -407,7 +407,7 @@
It is used for the global search.
.. classmethod:: ModelStorage.count()
.. classmethod:: ModelStorage.estimated_count()
Return an estimation of the number of records stored.
......
......@@ -259,7 +259,7 @@
else:
_, target_name = name.split('.', 1)
target_domain = [(target_name,) + tuple(domain[1:])]
if callable(Target.count) and Target.count() < _subquery_threshold:
if Target.estimated_count() < _subquery_threshold:
query = Target.search(target_domain, order=[], query=True)
return column.in_(query)
else:
......
......@@ -337,8 +337,7 @@
origin_where = origin.like(Model.__name__ + ',%')
origin = origin_field.sql_id(origin, Target)
use_in = (
callable(Target.count) and Target.count() < _subquery_threshold)
use_in = Target.estimated_count() < _subquery_threshold
if '.' not in name:
if value is None:
if use_in:
......
......@@ -1647,9 +1647,7 @@
main_table, _ = tables[None]
if count:
table = convert_from(None, tables)
if (limit is not None
and callable(cls.count)
and limit < cls.count()) or offset:
if (limit is not None and limit < cls.estimated_count()) or offset:
select = table.select(
Literal(1), where=expression, limit=limit, offset=offset
).select(Count(Literal('*')))
......@@ -1880,7 +1878,7 @@
'You can not update fields: "%s", "%s"' %
(field.left, field.right))
if callable(cls.count) and len(ids) < max(cls.count() / 4, 4):
if len(ids) < max(cls.estimated_count() / 4, 4):
for id_ in ids:
cls._update_tree(id_, field_name,
field.left, field.right)
......
......@@ -609,7 +609,7 @@
return process(domain)
@classmethod
def count(cls):
def estimated_count(cls):
"Returns the estimation of the number of records."
count = cls._count_cache.get(cls.__name__)
if count is None:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment