diff --git a/trytond/CHANGELOG b/trytond/CHANGELOG index 26591a1aa5..d2e6339c06 100644 --- a/trytond/CHANGELOG +++ b/trytond/CHANGELOG @@ -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 diff --git a/trytond/doc/ref/models.rst b/trytond/doc/ref/models.rst index 700a33804e..5bdb44c5ce 100644 --- a/trytond/doc/ref/models.rst +++ b/trytond/doc/ref/models.rst @@ -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. diff --git a/trytond/trytond/model/fields/many2one.py b/trytond/trytond/model/fields/many2one.py index 79a38cebb7..3f3f1ca15a 100644 --- a/trytond/trytond/model/fields/many2one.py +++ b/trytond/trytond/model/fields/many2one.py @@ -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: diff --git a/trytond/trytond/model/fields/one2many.py b/trytond/trytond/model/fields/one2many.py index 4a09777f17..c098d63c94 100644 --- a/trytond/trytond/model/fields/one2many.py +++ b/trytond/trytond/model/fields/one2many.py @@ -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: diff --git a/trytond/trytond/model/modelsql.py b/trytond/trytond/model/modelsql.py index 236af56bb7..21a3c5aec0 100644 --- a/trytond/trytond/model/modelsql.py +++ b/trytond/trytond/model/modelsql.py @@ -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) diff --git a/trytond/trytond/model/modelstorage.py b/trytond/trytond/model/modelstorage.py index 96d910bd33..931dca2fb2 100644 --- a/trytond/trytond/model/modelstorage.py +++ b/trytond/trytond/model/modelstorage.py @@ -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: