Optimized in 3 ways. 1) Local caching and compiling of all regexps. 2) URL level bucket caching 3) Tweaked canShowDebug to speed it up. This was ported back to the core.
108 lines
3.6 KiB
Perl
108 lines
3.6 KiB
Perl
|
|
use FindBin;
|
|
use strict;
|
|
use lib "$FindBin::Bin/../../lib";
|
|
#use DB;
|
|
|
|
use WebGUI::Test;
|
|
use WebGUI::Asset;
|
|
use WebGUI::PassiveAnalytics::Rule;
|
|
use WebGUI::Workflow::Activity::BucketPassiveAnalytics;
|
|
use WebGUI::Text;
|
|
|
|
use Test::More;
|
|
|
|
plan tests => 1; # increment this value for each test you create
|
|
|
|
my $session = WebGUI::Test->session;
|
|
$session->user({userId => 3});
|
|
|
|
my $workflow = WebGUI::Workflow->new($session, 'PassiveAnalytics000001');
|
|
my $activities = $workflow->getActivities();
|
|
##Note, they're in order, and the order is known.
|
|
$activities->[0]->set('deltaInterval', 100);
|
|
$activities->[1]->set('userId', 0); ##To disable sending emails
|
|
diag "Configured activities";
|
|
|
|
my $instance = WebGUI::Workflow::Instance->create($session,
|
|
{
|
|
workflowId => $workflow->getId,
|
|
skipSpectreNotification => 1,
|
|
priority => 1,
|
|
}
|
|
);
|
|
##Rule label, url, and regexp
|
|
my @ruleSets = (
|
|
['home', '/home', '^\/home' ],
|
|
['one', '/one', '^\/one$' ],
|
|
['two', '/two', '^\/two$' ],
|
|
['three', '/three', '^\/three$' ],
|
|
['end', '/blah/blah/end', 'end$' ],
|
|
['casa', '/home/casa', 'casa$' ],
|
|
['uno', '/one/uno', 'uno$' ],
|
|
['dos', '/two/dos', 'dos$' ],
|
|
['tres', '/three/tres', 'tres$' ],
|
|
['alpha', '/alpha/aee', '.alpha.aee' ],
|
|
['beta', '/beta/bee', '.beta.bee' ],
|
|
['gamma', '/gamma/cee', '.gamma.cee' ],
|
|
['delta', '/delta/dee', '.delta.dee' ],
|
|
['eee', '/epsilon/eee', 'eee$' ],
|
|
['thingy1', '/thingy?thingId=1', '^.thingy\?thingId=1' ],
|
|
['rogerRoger', '/roger/roger', '(?:\/roger){2}' ],
|
|
['roger', '/roger', '^\/roger' ],
|
|
['thingy2', '/thingy?thingId=2', '^.thingy\?thingId=2' ],
|
|
['beet', '/beta/beet', '.beta.beet' ],
|
|
['zero', '/yelnats', 'yelnats' ],
|
|
);
|
|
|
|
my @url2 = @ruleSets;
|
|
diag "Making rules";
|
|
while (my $spec = shift @url2) {
|
|
my ($bucket, undef, $regexp) = @{ $spec };
|
|
WebGUI::PassiveAnalytics::Rule->create($session, { bucketName => $bucket, regexp => $regexp });
|
|
}
|
|
|
|
my @urls = map {$_->[1]} @ruleSets;
|
|
diag "Making log data with " . scalar @urls . " urls";
|
|
loadLogData($session, @urls);
|
|
diag "Data logged";
|
|
|
|
##Build rulesets
|
|
|
|
##Now, run it and wait for it to finish
|
|
my $counter = 0;
|
|
diag time();
|
|
#DB::enable_profile();
|
|
PAUSE: while (my $retval = $instance->run()) {
|
|
diag $retval;
|
|
last PAUSE if $retval eq 'done';
|
|
last PAUSE if $counter++ >= 16;
|
|
}
|
|
#DB::disable_profile();
|
|
diag time();
|
|
|
|
ok(1, 'One test');
|
|
|
|
END {
|
|
$session->db->write('delete from passiveLog');
|
|
$session->db->write('delete from analyticRule');
|
|
$instance->delete;
|
|
}
|
|
|
|
sub loadLogData {
|
|
my ($session, @urls) = @_;
|
|
$session->db->write('delete from passiveLog');
|
|
my $insert = $session->db->prepare(
|
|
q!insert into passiveLog (userId, sessionId, timeStamp, url, assetId) VALUES (?,?,?,?,'assetId')!
|
|
);
|
|
my $logCount = 15000;
|
|
my $counter;
|
|
my $startTime = 1000;
|
|
my $numUrls = scalar @urls;
|
|
while ($counter++ < $logCount) {
|
|
my $index = int rand($numUrls);
|
|
my $url = $urls[$index];
|
|
$insert->execute([2, 25, $startTime, $url]);
|
|
$startTime += int(rand(10))+1;
|
|
}
|
|
}
|