Commit 8c4ead48 authored by Xavier Guimard's avatar Xavier Guimard

Split queries when number of sessions id too big (closes: #1171)

parent a6bc1cbc
#!/usr/bin/perl
package Test::Request;
use Mouse;
has userData => ( is => 'rw' );
has sessionInfo => ( is => 'rw' );
has id => ( is => 'rw' );
package main;
use Test::More;
use strict;
use lib 'lemonldap-ng-common/blib/lib';
use lib 'lemonldap-ng-handler/blib/lib';
use lib 'lemonldap-ng-portal/blib/lib';
use lib 'lemonldap-ng-manager/blib/lib';
require './lemonldap-ng-portal/t/test-lib.pm';
my $portal = LLNG::Manager::Test->new(
{
ini => {
configStorage => {
type => 'File',
dirName => 'e2e-tests/conf',
},
}
}
)->p;
my @chars = ( "A" .. "Z", "a" .. "z" );
foreach my $i ( 1 .. 100000 ) {
my $string;
$string .= $chars[ rand @chars ] for 1 .. 8;
my $req = Test::Request->new(
{
sessionInfo => {
_user => $string,
uid => $string,
cn => uc($string),
sn => $string,
mail => "$string\@badwolf.org",
}
}
);
$portal->setMacros($req);
$portal->store($req);
}
done_testing( count() );
......@@ -2,6 +2,9 @@
# Session explorer
###
# Max number of session to display (see overScheme)
max = 25
# Queries to do each type of display: each array item corresponds to the depth
# of opened nodes in the tree
schemes =
......@@ -50,6 +53,13 @@ schemes =
q.replace(/\&groupBy.*$/, '') + "&ipAddr=#{v}"
]
overScheme =
_whatToTrace: (t,v,l) ->
if level == 1
"#{t}=#{v}*&groupBy=substr(#{t},#{l})"
else
schemes._whatToTrace[level]
hiddenAttributes = '_password'
# Attributes to group in session display
......@@ -133,7 +143,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
$scope.stoggle = (scope) ->
node = scope.$modelValue
if node.nodes.length == 0
$scope.updateTree node.value, node.nodes, node.level, node.query
$scope.updateTree node.value, node.nodes, node.level, node.over, node.query
scope.toggle()
# Display selected session
......@@ -271,7 +281,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
# Function to update tree: download value of opened subkey
autoId = 0
$scope.updateTree = (value, node, level, currentQuery) ->
$scope.updateTree = (value, node, level, over, currentQuery) ->
$scope.waiting = true
# Query scheme selection:
......@@ -291,6 +301,14 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
# Build query using schemes
query = scheme[level] $scope.type, value, currentQuery
# If number of session exceeds "max" and overScheme exists, call it
if count > max and overScheme[$scope.type]
over++
query = overScheme[$scope.type] $scope.type, value, level, over, currentQuery
level = level - 1
else
over = 0
# Launch HTTP query
$http.get("#{scriptname}sessions/#{sessionType}?#{query}").then (response) ->
data = response.data
......@@ -302,6 +320,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
n.nodes = []
n.level = level + 1
n.query = query
n.over = over
# Date display in tree
if $scope.type.match /^(?:start|update)Time$/
......@@ -328,7 +347,7 @@ llapp.controller 'SessionsExplorerCtrl', ['$scope', '$translator', '$location',
$scope.data = []
$q.all [
$translator.init $scope.lang
$scope.updateTree '', $scope.data, 0
$scope.updateTree '', $scope.data, 0, 0
]
.then ->
$scope.waiting = false
......
......@@ -7,6 +7,14 @@
(function() {
var categories, hiddenAttributes, llapp, menu, schemes;
var toMuch = {
_whatToTrace: function(t, v, level, over) {
if(level===1) {
return t + "=" + v + "*&groupBy=substr(" + t + "," + (level+over) + ")";
}
return schemes._whatToTrace[level];
}
};
schemes = {
_whatToTrace: [
function(t, v) {
......@@ -147,7 +155,7 @@
var node;
node = scope.$modelValue;
if (node.nodes.length === 0) {
$scope.updateTree(node.value, node.nodes, node.level, node.query);
$scope.updateTree(node.value, node.nodes, node.level, node.over, node.query, node.count);
}
return scope.toggle();
};
......@@ -317,11 +325,19 @@
};
$scope.$on('$locationChangeSuccess', pathEvent);
autoId = 0;
$scope.updateTree = function(value, node, level, currentQuery) {
$scope.updateTree = function(value, node, level, over, currentQuery, count) {
var query, scheme;
$scope.waiting = true;
scheme = schemes[$scope.type] ? schemes[$scope.type] : $scope.type === 'updateTime' ? schemes.startTime : schemes._whatToTrace;
query = scheme[level]($scope.type, value, currentQuery);
if(count > 20 && toMuch[$scope.type]) {
over++;
query = toMuch[$scope.type]($scope.type, value, level, over, currentQuery);
level = level-1;
}
else {
over=0;
}
return $http.get(scriptname + "sessions/" + sessionType + "?" + query).then(function(response) {
var data, i, len, n, ref;
data = response.data;
......@@ -334,6 +350,7 @@
if (level < scheme.length - 1) {
n.nodes = [];
n.level = level + 1;
n.over = over;
n.query = query;
if ($scope.type.match(/^(?:start|update)Time$/)) {
n.title = n.value.replace(/^(\d{8})(\d{2})(\d{2})$/, '$2:$3').replace(/^(\d{8})(\d{2})(\d)$/, '$2:$30').replace(/^(\d{8})(\d{2})$/, '$2h').replace(/^(\d{4})(\d{2})(\d{2})/, '$1-$2-$3');
......@@ -353,7 +370,7 @@
$scope.init = function() {
$scope.waiting = true;
$scope.data = [];
return $q.all([$translator.init($scope.lang), $scope.updateTree('', $scope.data, 0)]).then(function() {
return $q.all([$translator.init($scope.lang), $scope.updateTree('', $scope.data, 0, 0)]).then(function() {
return $scope.waiting = false;
}, function(resp) {
return $scope.waiting = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment