[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:
Christophe Simonis 2014-08-12 18:38:55 +02:00
parent 726725a950
commit 1644708fe8
1 changed files with 2 additions and 2 deletions

View File

@ -2474,8 +2474,8 @@ class BaseModel(object):
self._create_table(cr)
has_rows = False
else:
cr.execute('SELECT COUNT(1) FROM "%s"' % (self._table,))
has_rows = cr.fetchone()[0]
cr.execute('SELECT min(id) FROM "%s"' % (self._table,))
has_rows = cr.fetchone()[0] is not None
cr.commit()
if self._parent_store: