[Rt-commit] rt branch, 4.0/makeclicky-cache, created. rt-4.0.19-75-g428ce8d
Kevin Falcone
falcone at bestpractical.com
Fri Apr 25 14:05:00 EDT 2014
The branch, 4.0/makeclicky-cache has been created
at 428ce8d95060f64c9cbecd7c0de0c87154bd5ccb (commit)
- Log -----------------------------------------------------------------
commit 428ce8d95060f64c9cbecd7c0de0c87154bd5ccb
Author: Kevin Falcone <falcone at bestpractical.com>
Date: Fri Apr 25 13:49:48 2014 -0400
Provide hook points to implement a MakeClicky cache.
MakeClicky is very expensive on long tickets, but no single part of it
is expensive. Having to match against large blocks of text and dispatch
to linking code just adds up slowly on long tickets. This provides rope
so that a cache can be implemented.
This is being tested in RTIR using mason file caching, but could easily
have a plugin to enable it in core or to switch to using some other
caching mechanism.
diff --git a/docs/extending/clickable_links.pod b/docs/extending/clickable_links.pod
index a6c56aa..dd80ff1 100644
--- a/docs/extending/clickable_links.pod
+++ b/docs/extending/clickable_links.pod
@@ -94,6 +94,15 @@ subroutine B<must escape> HTML.
A subroutine reference; modify it only if you have to. This can be used
to add pre- or post-processing around all actions.
+=item cache
+
+An undefined variable that should be replaced with a subroutine
+reference. This subroutine will be called twice, once with the arguments
+fetch => content_ref and once with store => content_ref. In the fetch
+case, if a cached copy is found, return the cached content, otherwise
+return a false value. When passed store, you should populate your cache
+with the content. The return value is ignored in this case.
+
=back
=head2 Actions' arguments
diff --git a/share/html/Elements/MakeClicky b/share/html/Elements/MakeClicky
index 1e24324..444b876 100644
--- a/share/html/Elements/MakeClicky
+++ b/share/html/Elements/MakeClicky
@@ -96,6 +96,8 @@ my $handle = sub {
}
};
+my $cache; # only defined via callback
+
# Hook to add more Clicky types
# XXX Have to have Page argument, as Mason gets caller wrong in Callback?
# This happens as we are in <%ONCE> block
@@ -104,6 +106,7 @@ $m->callback(
types => \@types,
actions => \%actions,
handle => \$handle,
+ cache => \$cache,
);
@@ -131,6 +134,15 @@ $html => undef
</%ARGS>
<%INIT>
return unless defined $$content;
+if ( defined $cache ) {
+ my $cached_content = $cache->(fetch => $content);
+ if ( $cached_content ) {
+ RT->Logger->debug("Found MakeClicky cache");
+ $$content = $cached_content;
+ return;
+ }
+}
+
unless ( $regexp ) {
RT::Interface::Web::EscapeUTF8( $content ) unless $html;
return;
@@ -165,6 +177,7 @@ substr( $$content, $pos ) = $escaper->( substr( $$content, $pos ) ) unless
($pos == length $$content) || $html;
pos($$content) = 0;
+$cache->(store => $content) if defined $cache;
</%INIT>
<%doc>
@@ -199,6 +212,14 @@ It will be provided with:
have to. This can be used to add pre- or post-processing around
all actions.
+ * 'cache': An undefined variable that should be replaced with a
+ subroutine reference. This subroutine will be called twice, once with
+ the arguments fetch => content_ref and once with store =>
+ content_ref. In the fetch case, if a cached copy is found, return the
+ cached content, otherwise return a false value. When passed store,
+ you should populate your cache with the content. The return value is
+ ignored in this case.
+
Read more about writing new actions in docs/extending/clickable_links.pod
</%doc>
-----------------------------------------------------------------------
More information about the rt-commit
mailing list