[Rt-commit] rt branch, lcore2, updated. f6781ad28ab1bea2213d4a89a1386408f9262c80
clkao at bestpractical.com
clkao at bestpractical.com
Tue Oct 27 04:33:13 EDT 2009
The branch, lcore2 has been updated
via f6781ad28ab1bea2213d4a89a1386408f9262c80 (commit)
from cbf84f35fac7477f47ca1e0d7a9bbca3fb736e50 (commit)
Summary of changes:
lib/RT/Lorzy/Dispatcher.pm | 38 +++++++++++++++++++++++++-------------
t/lorzy/action.t | 2 +-
t/lorzy/error.t | 2 ++
t/lorzy/update.t | 2 ++
4 files changed, 30 insertions(+), 14 deletions(-)
- Log -----------------------------------------------------------------
commit f6781ad28ab1bea2213d4a89a1386408f9262c80
Author: Chia-liang Kao <clkao at bestpractical.com>
Date: Tue Oct 27 16:11:57 2009 +0800
cache parsed rules to speed up tests for now.
diff --git a/lib/RT/Lorzy/Dispatcher.pm b/lib/RT/Lorzy/Dispatcher.pm
index 510ff2f..76e3a4b 100644
--- a/lib/RT/Lorzy/Dispatcher.pm
+++ b/lib/RT/Lorzy/Dispatcher.pm
@@ -1,7 +1,13 @@
package RT::Lorzy::Dispatcher;
use strict;
use warnings;
-#use base 'RT::Ruleset';
+use Cache::Simple::TimedExpiry;
+
+my $CACHE;
+
+sub flush_cache {
+ $CACHE = undef;
+}
sub reset_rules {
my $rules = RT::Model::RuleCollection->new( current_user => RT::CurrentUser->superuser);
@@ -12,19 +18,25 @@ sub reset_rules {
}
sub rules {
- my $rules = RT::Model::RuleCollection->new( current_user => RT::CurrentUser->superuser);
- $rules->unlimit;
- my $l = $RT::Lorzy::LCORE;
- return [ map {
- RT::Lorzy::RuleFactory->make_factory(
- { condition => $l->analyze_it($_->condition_code)->($l->env),
- prepare => $_->prepare_code ? $l->analyze_it($_->prepare_code)->($l->env) : undef,
- action => $l->analyze_it($_->action_code)->($l->env),
- description => $_->description,
- _stage => 'transaction_create' })
- } @$rules];
- return $rules;
+ unless ($CACHE) {
+ $CACHE = Cache::Simple::TimedExpiry->new();
+ $CACHE->expire_after(30);
+ }
+ unless ( $CACHE->has_key('allrules') ) {
+ my $rules = RT::Model::RuleCollection->new( current_user => RT::CurrentUser->superuser);
+ $rules->unlimit;
+ my $l = $RT::Lorzy::LCORE;
+ $CACHE->store( 'allrules' => [ map {
+ RT::Lorzy::RuleFactory->make_factory(
+ { condition => $l->analyze_it($_->condition_code)->($l->env),
+ prepare => $_->prepare_code ? $l->analyze_it($_->prepare_code)->($l->env) : undef,
+ action => $l->analyze_it($_->action_code)->($l->env),
+ description => $_->description,
+ _stage => 'transaction_create' })
+ } @$rules]);
+ }
+ return $CACHE->fetch( 'allrules' );
}
1;
diff --git a/t/lorzy/action.t b/t/lorzy/action.t
index fcad561..0baae0b 100644
--- a/t/lorzy/action.t
+++ b/t/lorzy/action.t
@@ -43,7 +43,7 @@ RT::Lorzy::Dispatcher->reset_rules;
my $rule = RT::Model::Rule->new( current_user => RT->system_user );
$rule->create( condition_code => $on_created_lcore,
action_code => $auto_reply_lcore );
-
+RT::Lorzy::Dispatcher->flush_cache;
my $queue = RT::Model::Queue->new(current_user => RT->system_user);
my ($queue_id) = $queue->create( name => 'lorzy');
ok( $queue_id, 'queue created' );
diff --git a/t/lorzy/error.t b/t/lorzy/error.t
index 079485a..1c6cb89 100644
--- a/t/lorzy/error.t
+++ b/t/lorzy/error.t
@@ -50,6 +50,8 @@ $rule->create( description => 'test worky action',
condition_code => '(lambda (ticket transaction) 1)',
action_code => '(lambda (ticket transaction context) (inc-hint-run context))' );
+RT::Lorzy::Dispatcher->flush_cache;
+
my ($txn_id, $tmsg, $txn) = $ticket->comment(content => 'lorzy lorzy in the code');
my ($this_rule) = grep { $_->description eq 'test fail action'} @{$txn->rules};
diff --git a/t/lorzy/update.t b/t/lorzy/update.t
index 937d2a8..d7f6b29 100644
--- a/t/lorzy/update.t
+++ b/t/lorzy/update.t
@@ -52,6 +52,8 @@ my $rule = RT::Model::Rule->new( current_user => RT->system_user );
$rule->create( condition_code => $on_created_lcore,
action_code => $update_ticket_lcore );
+RT::Lorzy::Dispatcher->flush_cache;
+
my $queue = RT::Model::Queue->new(current_user => RT->system_user);
my ($queue_id) = $queue->create( name => 'lorzy');
ok( $queue_id, 'queue created' );
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list