diff --git a/docker-compose.yml b/docker-compose.yml index 35c52b73..20e3e649 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,6 +10,7 @@ services: command: make test environment: SQLALCHEMY_DATABASE_URI: postgresql://lemur:lemur@postgres:5432/lemur + VIRTUAL_ENV: 'true' postgres: image: postgres:9.4 diff --git a/lemur/database.py b/lemur/database.py index 13e67710..8efd4b95 100644 --- a/lemur/database.py +++ b/lemur/database.py @@ -268,6 +268,11 @@ def clone(model): def get_count(q): + """ + Count the number of rows in a table. More efficient than count(*) + :param q: + :return: + """ count_q = q.statement.with_only_columns([func.count()]).order_by(None) count = q.session.execute(count_q).scalar() return count