Rename ModelStorage.count into ModelStorage.estimated_count

count is too common name for a standard method like #12016 reveals.
This commit is contained in:
Cédric Krier
2023-01-17 23:01:08 +01:00
parent 0b67a61607
commit 389ad47590
6 changed files with 7 additions and 9 deletions
+1
View File
@@ -1,3 +1,4 @@
* 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
+1 -1
View File
@@ -407,7 +407,7 @@ Class methods:
It is used for the global search.
.. classmethod:: ModelStorage.count()
.. classmethod:: ModelStorage.estimated_count()
Return an estimation of the number of records stored.
+1 -1
View File
@@ -259,7 +259,7 @@ class Many2One(Field):
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:
+1 -2
View File
@@ -337,8 +337,7 @@ class One2Many(Field):
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:
+2 -4
View File
@@ -1647,9 +1647,7 @@ class ModelSQL(ModelStorage):
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 @@ class ModelSQL(ModelStorage):
'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)
+1 -1
View File
@@ -609,7 +609,7 @@ class ModelStorage(Model):
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: