Răsfoiți Sursa

Optimize post-in-post render

George Baugh 3 ani în urmă
părinte
comite
f94452b133
1 a modificat fișierele cu 17 adăugiri și 15 ștergeri
  1. 17 15
      lib/Trog/Routes/HTML.pm

+ 17 - 15
lib/Trog/Routes/HTML.pm

@@ -843,26 +843,28 @@ sub posts ($query, $render_cb, $direct=0) {
     my $fmt = $query->{format} || '';
     return _rss($query,\@posts) if $fmt eq 'rss';
 
+    my $child_processor = Text::Xslate->new(
+        # Prevent a recursive descent.  If the renderer is hit again, just do nothing
+        # XXX unfortunately if the post tries to include itself, it will die.
+        function => {
+            embed => sub {
+                my ($this_id, $style) = @_;
+                $style //= 'embed';
+                # If instead the style is 'content', then we will only show the content w/ no formatting, and no title.
+                return Text::Xslate::mark_raw(Trog::Routes::HTML::posts(
+                    { route => "/post/$this_id", style => $style },
+                    sub {},
+                1));
+            },
+        }
+    );
+
     my $processor = Text::Xslate->new(
         path   => $template_dir,
         function => {
             render_it => sub {
                 my ($template_string, $options) = @_;
-                return Text::Xslate->new(
-                    # Prevent a recursive descent.  If the renderer is hit again, just do nothing
-                    # XXX unfortunately if the post tries to include itself, it will die.
-                    function => {
-                        embed => sub {
-                            my ($this_id, $style) = @_;
-                            $style //= 'embed';
-                            # If instead the style is 'content', then we will only show the content w/ no formatting, and no title.
-                            return Text::Xslate::mark_raw(Trog::Routes::HTML::posts(
-                                { route => "/post/$this_id", style => $style },
-                                sub {},
-                            1));
-                        },
-                    },
-                )->render_string($template_string,$options);
+                return $child_processor->render_string($template_string,$options);
             },
         },
     );