Merge pull request #1722 from coreos-inc/logentry-index
Add an index for lookup by account to log entries
This commit is contained in:
commit
aa2066e3f5
4 changed files with 36 additions and 14 deletions
|
@ -730,10 +730,9 @@ class LogEntry(BaseModel):
|
||||||
database = db
|
database = db
|
||||||
read_slaves = (read_slave,)
|
read_slaves = (read_slave,)
|
||||||
indexes = (
|
indexes = (
|
||||||
# create an index on repository and date
|
(('account', 'datetime'), False),
|
||||||
|
(('performer', 'datetime'), False),
|
||||||
(('repository', 'datetime'), False),
|
(('repository', 'datetime'), False),
|
||||||
|
|
||||||
# create an index on repository, date and kind
|
|
||||||
(('repository', 'datetime', 'kind'), False),
|
(('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
|
import json
|
||||||
|
|
||||||
from calendar import timegm
|
from calendar import timegm
|
||||||
from peewee import JOIN_LEFT_OUTER, SQL, fn
|
from peewee import JOIN_LEFT_OUTER, fn
|
||||||
from datetime import datetime, timedelta, date
|
from datetime import datetime, timedelta
|
||||||
from cachetools import lru_cache
|
from cachetools import lru_cache
|
||||||
|
|
||||||
from data.database import LogEntry, LogEntryKind, User, RepositoryActionCount, db
|
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,
|
def _logs_query(selections, start_time, end_time, performer=None, repository=None, namespace=None,
|
||||||
ignore=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)
|
joined = joined.where(LogEntry.performer == performer)
|
||||||
|
|
||||||
if namespace:
|
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:
|
if ignore:
|
||||||
kind_map = get_log_entry_kinds()
|
kind_map = get_log_entry_kinds()
|
||||||
|
|
|
@ -13,7 +13,6 @@ angular.module('quay').directive('logsView', function () {
|
||||||
'user': '=user',
|
'user': '=user',
|
||||||
'makevisible': '=makevisible',
|
'makevisible': '=makevisible',
|
||||||
'repository': '=repository',
|
'repository': '=repository',
|
||||||
'performer': '=performer',
|
|
||||||
'allLogs': '@allLogs'
|
'allLogs': '@allLogs'
|
||||||
},
|
},
|
||||||
controller: function($scope, $element, $sce, Restangular, ApiService, TriggerService,
|
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 += '?starttime=' + encodeURIComponent(getDateString($scope.options.logStartDate));
|
||||||
url += '&endtime=' + encodeURIComponent(getDateString($scope.options.logEndDate));
|
url += '&endtime=' + encodeURIComponent(getDateString($scope.options.logEndDate));
|
||||||
|
|
||||||
if ($scope.performer) {
|
|
||||||
url += '&performer=' + encodeURIComponent($scope.performer.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -397,7 +391,6 @@ angular.module('quay').directive('logsView', function () {
|
||||||
$scope.$watch('user', update);
|
$scope.$watch('user', update);
|
||||||
$scope.$watch('repository', update);
|
$scope.$watch('repository', update);
|
||||||
$scope.$watch('makevisible', update);
|
$scope.$watch('makevisible', update);
|
||||||
$scope.$watch('performer', update);
|
|
||||||
|
|
||||||
$scope.$watch('options.logStartDate', update);
|
$scope.$watch('options.logStartDate', update);
|
||||||
$scope.$watch('options.logEndDate', update);
|
$scope.$watch('options.logEndDate', update);
|
||||||
|
|
Reference in a new issue