Add an index for lookup by account to log entries
Also fixes the query to require one less join
This commit is contained in:
parent
d9b65b88e9
commit
0f46230493
4 changed files with 36 additions and 14 deletions
|
@ -730,10 +730,9 @@ class LogEntry(BaseModel):
|
|||
database = db
|
||||
read_slaves = (read_slave,)
|
||||
indexes = (
|
||||
# create an index on repository and date
|
||||
(('account', 'datetime'), False),
|
||||
(('performer', 'datetime'), False),
|
||||
(('repository', 'datetime'), False),
|
||||
|
||||
# create an index on repository, date and kind
|
||||
(('repository', 'datetime', 'kind'), False),
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
"""Add logentry index for lookup by account
|
||||
|
||||
Revision ID: 8981dabd329f
|
||||
Revises: 790d91952fa8
|
||||
Create Date: 2016-08-12 16:50:15.816120
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '8981dabd329f'
|
||||
down_revision = '790d91952fa8'
|
||||
|
||||
from alembic import op
|
||||
|
||||
def upgrade(tables):
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_index('logentry_account_id_datetime', 'logentry', ['account_id', 'datetime'], unique=False)
|
||||
op.create_index('logentry_performer_id_datetime', 'logentry', ['performer_id', 'datetime'], unique=False)
|
||||
### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade(tables):
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index('logentry_account_id_datetime', table_name='logentry')
|
||||
op.drop_index('logentry_performer_id_datetime', table_name='logentry')
|
||||
### end Alembic commands ###
|
|
@ -1,12 +1,12 @@
|
|||
import json
|
||||
|
||||
from calendar import timegm
|
||||
from peewee import JOIN_LEFT_OUTER, SQL, fn
|
||||
from datetime import datetime, timedelta, date
|
||||
from peewee import JOIN_LEFT_OUTER, fn
|
||||
from datetime import datetime, timedelta
|
||||
from cachetools import lru_cache
|
||||
|
||||
from data.database import LogEntry, LogEntryKind, User, RepositoryActionCount, db
|
||||
from data.model import config
|
||||
from data.model import config, user, DataModelException
|
||||
|
||||
def _logs_query(selections, start_time, end_time, performer=None, repository=None, namespace=None,
|
||||
ignore=None):
|
||||
|
@ -22,7 +22,11 @@ def _logs_query(selections, start_time, end_time, performer=None, repository=Non
|
|||
joined = joined.where(LogEntry.performer == performer)
|
||||
|
||||
if namespace:
|
||||
joined = joined.join(User, on=(User.username == namespace))
|
||||
namespace_user = user.get_user_or_org(namespace)
|
||||
if namespace_user is None:
|
||||
raise DataModelException('Invalid namespace requested')
|
||||
|
||||
joined = joined.where(LogEntry.account == namespace_user.id)
|
||||
|
||||
if ignore:
|
||||
kind_map = get_log_entry_kinds()
|
||||
|
|
|
@ -13,7 +13,6 @@ angular.module('quay').directive('logsView', function () {
|
|||
'user': '=user',
|
||||
'makevisible': '=makevisible',
|
||||
'repository': '=repository',
|
||||
'performer': '=performer',
|
||||
'allLogs': '@allLogs'
|
||||
},
|
||||
controller: function($scope, $element, $sce, Restangular, ApiService, TriggerService,
|
||||
|
@ -313,11 +312,6 @@ angular.module('quay').directive('logsView', function () {
|
|||
|
||||
url += '?starttime=' + encodeURIComponent(getDateString($scope.options.logStartDate));
|
||||
url += '&endtime=' + encodeURIComponent(getDateString($scope.options.logEndDate));
|
||||
|
||||
if ($scope.performer) {
|
||||
url += '&performer=' + encodeURIComponent($scope.performer.name);
|
||||
}
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
|
@ -397,7 +391,6 @@ angular.module('quay').directive('logsView', function () {
|
|||
$scope.$watch('user', update);
|
||||
$scope.$watch('repository', update);
|
||||
$scope.$watch('makevisible', update);
|
||||
$scope.$watch('performer', update);
|
||||
|
||||
$scope.$watch('options.logStartDate', update);
|
||||
$scope.$watch('options.logEndDate', update);
|
||||
|
|
Reference in a new issue