Skip to content
Browse files

Added a Rules file for prettier logic encapsulation.

Forcibly turn on module caching when a rule requires it.
Log a message when a rule requires SSIs.

TODO: a specific rule needs to be created for evaluating SSI and module caching.
  • Loading branch information...
1 parent 7cc2021 commit 979fa9ab936d7783b98e077f9ea2a2b4969f40c0 @byrnereese byrnereese committed
Showing with 64 additions and 8 deletions.
  1. +6 −0 CHANGE_LOG.md
  2. +1 −1 Makefile.PL
  3. +13 −7 plugins/Optimizer/config.yaml
  4. +44 −0 plugins/Optimizer/lib/MT/Theme/Optimizer/Rules.pm
View
6 CHANGE_LOG.md
@@ -0,0 +1,6 @@
+# Changes Introduced in 0.2
+
+* Forcibly enable template module caching for rules that depend upon
+ it being on.
+* Log a warning/info message about enabling server side includes and
+ selecting the desired include system.
View
2 Makefile.PL
@@ -2,6 +2,6 @@ use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'Template Optimizer',
- VERSION => '0.1',
+ VERSION => '0.2',
DISTNAME => 'Optimizer',
);
View
20 plugins/Optimizer/config.yaml
@@ -1,7 +1,7 @@
id: Optimizer
name: 'Template Optimizer'
description: 'This plugin has the ability to sift through your system, offer recommendations for you can improve the publishing performance of your system and then optionally make them.'
-version: 0.1
+version: 0.2
applications:
cms:
@@ -77,8 +77,7 @@ optimizations:
order: 3
condition: >
sub { $_[0]->type eq 'widget' && ($_[0]->name =~ /recent entries/i) && $_[0]->cache_expire_type != 2 && $_[0]->cache_expire_event ne 'entry' }
- handler: >
- sub { $_[0]->cache_expire_type( 2 ); $_[0]->cache_expire_event('entry'); }
+ handler: $Optimizer::MT::Theme::Optimizer::Rules::recent_entries_handler
recent_comments:
label: "Recent Comments widget should be cached"
short_description: >
@@ -87,8 +86,7 @@ optimizations:
order: 3
condition: >
sub { $_[0]->type eq 'widget' && ($_[0]->name =~ /recent comments/i) && $_[0]->cache_expire_type != 2 && $_[0]->cache_expire_event ne 'comment' }
- handler: >
- sub { $_[0]->cache_expire_type( 2 ); $_[0]->cache_expire_event('comment'); }
+ handler: $Optimizer::MT::Theme::Optimizer::Rules::recent_comments_handler
recent_ssi:
label: "Recent Comments and Entries widget should be SSIs"
short_description: >
@@ -97,8 +95,7 @@ optimizations:
order: 4
condition: >
sub { $_[0]->type eq 'widget' && ($_[0]->name =~ /recent (comments|entries)/i) && $_[0]->include_with_ssi == 0 }
- handler: >
- sub { $_[0]->include_with_ssi( 1 ); }
+ handler: $Optimizer::MT::Theme::Optimizer::Rules::recent_ssi_handler
archives_pq:
label: "Publish Archive Index in the background"
short_description: >
@@ -109,3 +106,12 @@ optimizations:
sub { require MT::PublishOption; $_[0]->type eq 'index' && ($_[0]->identifier eq 'archive_index' || $_[0]->name =~ /Archive Index/i) && $_[0]->build_type != MT::PublishOption::ASYNC() }
handler: >
sub { require MT::PublishOption; $_[0]->build_type( MT::PublishOption::ASYNC() ); }
+ test:
+ label: "Test Rule"
+ short_description: >
+ sub { return 'test rule' }
+ help: 'test'
+ order: 6
+ condition: $Optimizer::MT::Theme::Optimizer::Rules::test_cond
+ handler: $Optimizer::MT::Theme::Optimizer::Rules::test_handler
+
View
44 plugins/Optimizer/lib/MT/Theme/Optimizer/Rules.pm
@@ -0,0 +1,44 @@
+package MT::Theme::Optimizer::Rules;
+
+use strict;
+
+sub recent_ssi_handler {
+ my ($tmpl) = @_;
+ $tmpl->include_with_ssi( 1 );
+ my $blog = $tmpl->blog();
+ if ($blog->include_system eq '') {
+ my $req = MT::Request->instance;
+ unless ($req->stash('warned_about_ssi')) {
+ MT->log({ blog_id => $blog->id,
+ message => 'In order to take advantage of certain template optimizations you need to turn on "Server Side Includes" in your blog preferences.' });
+ $req->stash('warned_about_ssi',1);
+ }
+ }
+}
+
+sub recent_comments_handler {
+ my ($tmpl) = @_;
+ $tmpl->cache_expire_type( 2 );
+ $tmpl->cache_expire_event('comment');
+
+ my $blog = $tmpl->blog();
+ unless ($blog->include_cache) {
+ $blog->include_cache(1);
+ $blog->save;
+ }
+}
+
+sub recent_entries_handler {
+ my ($tmpl) = @_;
+ $tmpl->cache_expire_type( 2 );
+ $tmpl->cache_expire_event('entry');
+
+ my $blog = $tmpl->blog();
+ unless ($blog->include_cache) {
+ $blog->include_cache(1);
+ $blog->save;
+ }
+}
+
+1;
+__END__

0 comments on commit 979fa9a

Please sign in to comment.
Something went wrong with that request. Please try again.