diff --git a/data/database.py b/data/database.py index d96082d89..94d469f07 100644 --- a/data/database.py +++ b/data/database.py @@ -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), ) diff --git a/data/migrations/versions/8981dabd329f_add_logentry_index_for_lookup_by_account.py b/data/migrations/versions/8981dabd329f_add_logentry_index_for_lookup_by_account.py new file mode 100644 index 000000000..4434982d1 --- /dev/null +++ b/data/migrations/versions/8981dabd329f_add_logentry_index_for_lookup_by_account.py @@ -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 ### diff --git a/data/model/log.py b/data/model/log.py index 886610747..d927f2ad7 100644 --- a/data/model/log.py +++ b/data/model/log.py @@ -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() diff --git a/static/js/directives/ui/logs-view.js b/static/js/directives/ui/logs-view.js index ff7c0ee83..4c6321c63 100644 --- a/static/js/directives/ui/logs-view.js +++ b/static/js/directives/ui/logs-view.js @@ -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);