[IMP] models.py: _auto_init: accelerate row existance check
Using `COUNT(1)` on big table can be slow. Use `min(id)` which use pkey index to have a quicker response
This commit is contained in:
parent
726725a950
commit
1644708fe8
|
@ -2474,8 +2474,8 @@ class BaseModel(object):
|
||||||
self._create_table(cr)
|
self._create_table(cr)
|
||||||
has_rows = False
|
has_rows = False
|
||||||
else:
|
else:
|
||||||
cr.execute('SELECT COUNT(1) FROM "%s"' % (self._table,))
|
cr.execute('SELECT min(id) FROM "%s"' % (self._table,))
|
||||||
has_rows = cr.fetchone()[0]
|
has_rows = cr.fetchone()[0] is not None
|
||||||
|
|
||||||
cr.commit()
|
cr.commit()
|
||||||
if self._parent_store:
|
if self._parent_store:
|
||||||
|
|
Loading…
Reference in New Issue