improve calendar performances

This commit is contained in:
ziirish 2017-02-06 21:23:31 +01:00
parent 0d11afb342
commit 510fdd0184
7 changed files with 44 additions and 47 deletions

View file

@ -22,6 +22,7 @@ from ..sessions import session_manager
from ..ext.async import celery
from ..ext.cache import cache
from ..config import config
from ..decorators import browser_cache
from six import iteritems
from zlib import adler32
@ -754,6 +755,7 @@ class AsyncHistory(History):
"""
@cache.cached(timeout=1800, key_prefix=cache_key)
@browser_cache(1800)
@ns.marshal_with(
History.history_fields,
code=200,
@ -845,6 +847,7 @@ class AsyncClientsReport(ClientsReport):
"""
@api.cache.cached(timeout=1800, key_prefix=cache_key)
@browser_cache(1800)
@ns.marshal_with(
ClientsReport.report_fields,
code=200,

View file

@ -11,6 +11,7 @@ from . import api, cache_key
from ..server import BUIServer # noqa
from .custom import fields, Resource
from ..exceptions import BUIserverException
from ..decorators import browser_cache
from ..ext.cache import cache
from six import iteritems
@ -325,6 +326,7 @@ class About(Resource):
})
@cache.cached(timeout=3600, key_prefix=cache_key)
@browser_cache(3600)
@ns.marshal_with(about_fields, code=200, description='Success')
@ns.expect(parser)
def get(self, server=None):
@ -430,6 +432,7 @@ class History(Resource):
})
@cache.cached(timeout=1800, key_prefix=cache_key)
@browser_cache(1800)
@ns.marshal_list_with(history_fields, code=200, description='Success')
@ns.expect(parser)
@ns.doc(

View file

@ -721,7 +721,7 @@ class Burp(BUIbackend):
if 'bytes' not in res:
res['bytes'] = 0
if viewkeys(res) & {'start', 'estimated_bytes', 'bytes_in'}:
if set(['start', 'estimated_bytes', 'bytes_in']) <= set(viewkeys(res)):
try:
diff = time.time() - int(res['start'])
byteswant = int(res['estimated_bytes'])

View file

@ -640,8 +640,9 @@ class Burp(Burp1):
return ret
backup = None
phases = ['working', 'finishing']
for back in client['backups']:
if 'flags' in back and 'working' in back['flags']:
if 'flags' in back and any([x in back['flags'] for x in phases]):
backup = back
break
# check we found a working backup
@ -681,9 +682,14 @@ class Burp(Burp1):
else:
ret[name] = counter['count']
for phase in phases:
if phase in backup['flags']:
ret['phase'] = phase
break
if 'bytes' not in ret:
ret['bytes'] = 0
if viewkeys(ret) & {'time_start', 'estimated_bytes', 'bytes'}:
if set(['time_start', 'estimated_bytes', 'bytes']) <= set(viewkeys(ret)):
try:
diff = time.time() - int(ret['time_start'])
byteswant = int(ret['estimated_bytes'])

View file

@ -14,8 +14,6 @@
</ul>
<br />
<h1 class="page-header">Calendar{% if cname %} of {{ cname }}{% if server %} on {{ server }}{% endif %}{% elif server %} of {{ server }}{% endif %}</h1>
<div class="row placeholders" ng-controller="CalendarCtrl">
<div ui-calendar="uiConfig.calendar" ng-model="eventSources" calendar="backups" id="bui-calendar"></div>
</div>
<div id='calendar'></div>
</div>
{% endblock %}

View file

@ -19,54 +19,44 @@ var _client = function() {};
var _clients = function() {};
var _servers = function() {};
var app = angular.module('MainApp', ['ngSanitize', 'ui.calendar', 'ui.bootstrap']);
$(document).ready(function() {
app.controller('CalendarCtrl', function($scope, $http, $compile, uiCalendarConfig) {
$scope.eventSources = [];
$scope.eventRender = function( event, element, view ) {
myEventRender = function( event, element, view ) {
element.attr({
'tooltip-placement': 'bottom',
'uib-tooltip': event.title+' Duration: '+_time_human_readable((new Date(event.end) - new Date(event.start))/1000),
'tooltip-append-to-body': true,
'title': event.title+', Duration: '+_time_human_readable((new Date(event.end) - new Date(event.start))/1000),
});
$compile(element)($scope);
};
$scope.uiConfig = {
calendar: {
{{ macros.translate_calendar() }}
editable: false,
eventLimit: true,
firstDay: 1,
header:{
left: 'month,listWeek',
center: 'title',
right: 'today prev,next'
},
monthNames: moment.months(),
monthNamesShort: moment.monthsShort(),
dayNames: moment.weekdays(),
dayNamesShort: moment.weekdaysShort(),
eventRender: $scope.eventRender,
viewRender: function(view, element) {
$scope.fetchEvents(view.start.format(), view.end.format());
}
}
};
$scope.fetchEvents = function(start, end) {
fetchEvents = function(start, end) {
{% if config.WITH_CELERY -%}
var feed_url = '{{ url_for("api.async_history", client=cname, server=server) }}?start='+start+'&end='+end;
{% else -%}
var feed_url = '{{ url_for("api.history", client=cname, server=server) }}?start='+start+'&end='+end;
{% endif -%}
$http.get(feed_url, { headers: { 'X-From-UI': true } })
.success(function(data, status, headers, config) {
$scope.eventSources.splice(0);
angular.forEach(data, function(source) {
$scope.eventSources.push(source);
$.get(feed_url)
.done(function(data) {
cal = $('#calendar')
cal.fullCalendar('removeEventSources');
$.each(data, function(i, source) {
source.cache = true;
cal.fullCalendar('addEventSource', source);
});
});
};
$('#calendar').fullCalendar({
{{ macros.translate_calendar() }}
editable: false,
eventLimit: true,
firstDay: 1,
header:{
left: 'month,listWeek',
center: 'title',
right: 'today prev,next'
},
eventRender: myEventRender,
viewRender: function(view, element) {
fetchEvents(view.start.format(), view.end.format());
}
});
});

View file

@ -79,7 +79,7 @@
<script src="{{ url_for('bower.static', filename='datatables.net-responsive/js/dataTables.responsive.js') }}"></script>
<script src="{{ url_for('bower.static', filename='datatables.net-responsive-bs/js/responsive.bootstrap.js') }}"></script>
{% endif -%}
{% if about or live or calendar or settings or ng_controller -%}
{% if about or live or settings or ng_controller -%}
<!-- configuration angular views
================================================== -->
<script src="{{ url_for('bower.static', filename='angular/angular.min.js') }}"></script>
@ -110,9 +110,6 @@
{% if calendar -%}
<!-- calendar Javascript
================================================== -->
<script src="{{ url_for('bower.static', filename='angular-bootstrap/ui-bootstrap.min.js') }}"></script>
<script src="{{ url_for('bower.static', filename='angular-bootstrap/ui-bootstrap-tpls.min.js') }}"></script>
<script src="{{ url_for('bower.static', filename='angular-ui-calendar/src/calendar.js') }}"></script>
<script src="{{ url_for('bower.static', filename='fullcalendar/dist/fullcalendar.min.js') }}"></script>
<script src="{{ url_for('bower.static', filename='fullcalendar/dist/gcal.min.js') }}"></script>
{% if g.locale and g.locale != 'en' -%}