Simplify event count by stack

The previous event count by stack used default sqlalchemy ORM count
method, which works fine but uses a subquery and loads all columns. We
can simplify it by using the func.count utility.

Change-Id: Ib3da569022cd4e13d0c7b13d98a4eb766cdb1a61
This commit is contained in:
Thomas Herve 2016-02-15 09:56:05 +01:00
parent 681df8eb00
commit 165ce0b272
1 changed files with 3 additions and 1 deletions

View File

@ -23,6 +23,7 @@ from oslo_utils import timeutils
import osprofiler.sqlalchemy
import six
import sqlalchemy
from sqlalchemy import func
from sqlalchemy import orm
from sqlalchemy.orm import aliased as orm_aliased
from sqlalchemy.orm import session as orm_session
@ -759,7 +760,8 @@ def _events_filter_and_page_query(context, query,
def event_count_all_by_stack(context, stack_id):
return _query_all_by_stack(context, stack_id).count()
query = model_query(context, func.count(models.Event.id))
return query.filter_by(stack_id=stack_id).scalar()
def _delete_event_rows(context, stack_id, limit):