OSDN Git Service

use cache in Controller::Timeline, Controller::API::Coment
authorhylom <hylom@users.sourceforge.jp>
Mon, 9 Oct 2017 15:07:08 +0000 (00:07 +0900)
committerhylom <hylom@users.sourceforge.jp>
Mon, 9 Oct 2017 15:07:08 +0000 (00:07 +0900)
src/newslash_web/lib/Newslash/Web/Controller/API/Comment.pm
src/newslash_web/lib/Newslash/Web/Controller/Timeline.pm

index 062b5a6..dcc89e8 100644 (file)
@@ -135,7 +135,9 @@ sub get {
         $value = $data->{cid} || $data->{comment_id} || $data->{id};
     }
 
-    my $rs = $comments->select($key => $value);
+    #my $rs = $comments->select($key => $value);
+    my $rs = $c->model_cache->select("comments", 5,
+                                     $key => $value);
     $c->apply_seclev_filter("comments", $rs);
 
     if (!defined $rs) {
index 93b54fc..14e9c4e 100644 (file)
@@ -7,6 +7,8 @@ use DateTime::Format::MySQL;
 use Newslash::Util::Formatters;
 use Newslash::Util::Items;
 
+use constant CACHE_SEC => 30;
+
 sub _make_navitem {
     my ($self, $item) = @_;
     return if !$item;
@@ -82,11 +84,17 @@ sub stories {
     my $show_future = $user->{is_admin} ? 1 : 0;
     my $show_nonpublic = $user->{is_admin} ? 1 : 0;
 
-    my $items = $c->model('stories')->select(show_future => $show_future,
-                                               show_nonpublic => $show_nonpublic,
-                                               limit => $limit + 1,
-                                               order_by => {create_time => 'desc'},
-                                            );
+    # my $items = $c->model('stories')->select(show_future => $show_future,
+    #                                            show_nonpublic => $show_nonpublic,
+    #                                            limit => $limit + 1,
+    #                                            order_by => {create_time => 'desc'},
+    #                                         );
+    my $items = $c->model_cache->select("stories", CACHE_SEC,
+                                        show_future => $show_future,
+                                        show_nonpublic => $show_nonpublic,
+                                        limit => $limit + 1,
+                                        order_by => {create_time => 'desc'},
+                                        );
 
     $c->_render_timeline(items => $items,
                          limit => $limit);
@@ -95,7 +103,9 @@ sub stories {
 sub recent {
     my $c = shift;
     my $limit = $c->_get_config("item_per_page", 10);
-    my $items = $c->model('timeline')->select(limit => $limit);
+    #my $items = $c->model('timeline')->select(limit => $limit);
+    my $items = $c->model_cache->select('timeline', CACHE_SEC,
+                                        limit => $limit);
 
     $c->_render_timeline(items => $items,
                          limit => $limit,
@@ -122,9 +132,14 @@ sub popular {
         $popular_period = {days => 3};
     }
 
-    my $items = $c->model('timeline')->select(limit => $limit,
-                                              order_by => {popularity => "DESC"},
-                                              %$popular_period);
+    #my $items = $c->model('timeline')->select(limit => $limit,
+    #                                          order_by => {popularity => "DESC"},
+    #                                          %$popular_period);
+    my $items = $c->model_cache->select('timeline', CACHE_SEC,
+                                        limit => $limit,
+                                        order_by => {popularity => "DESC"},
+                                        %$popular_period);
+
     $c->_render_timeline(items => $items,
                          limit => $limit,
                          title => "人気");
@@ -133,8 +148,11 @@ sub popular {
 sub comments {
     my $c = shift;
     my $limit = $c->_get_config("item_per_page", 10);
-    my $items = $c->model('comments')->select(limit => $limit + 1,
-                                              order_by => {create_time => 'DESC'});
+    #my $items = $c->model('comments')->select(limit => $limit + 1,
+    #                                          order_by => {create_time => 'DESC'});
+    my $items = $c->model_cache->select('comments', CACHE_SEC,
+                                        limit => $limit + 1,
+                                        order_by => {create_time => 'DESC'});
 
     $c->_render_timeline(items => $items,
                          limit => $limit,
@@ -145,8 +163,11 @@ sub comments {
 sub journals {
     my $c = shift;
     my $limit = $c->_get_config("item_per_page", 10);
-    my $items = $c->model('journals')->select(limit => $limit + 1,
-                                              order_by => {create_time => 'DESC'});
+    #my $items = $c->model('journals')->select(limit => $limit + 1,
+    #                                          order_by => {create_time => 'DESC'});
+    my $items = $c->model_cache->select('journals', CACHE_SEC,
+                                        limit => $limit + 1,
+                                        order_by => {create_time => 'DESC'});
 
     $c->_render_timeline(items => $items,
                          limit => $limit,
@@ -156,8 +177,11 @@ sub journals {
 sub submissions {
     my $c = shift;
     my $limit = $c->_get_config("item_per_page", 10);
-    my $items = $c->model('submissions')->select(limit => $limit + 1,
-                                                 order_by => {create_time => 'DESC'});
+    #my $items = $c->model('submissions')->select(limit => $limit + 1,
+    #                                             order_by => {create_time => 'DESC'});
+    my $items = $c->model_cache->select('submissions', CACHE_SEC,
+                                        limit => $limit + 1,
+                                        order_by => {create_time => 'DESC'});
 
     $c->_render_timeline(items => $items,
                          limit => $limit,
@@ -167,8 +191,11 @@ sub submissions {
 sub polls {
     my $c = shift;
     my $limit = $c->_get_config("item_per_page", 10);
-    my $items = $c->model('polls')->select(limit => $limit + 1,
-                                           order_by => {create_time => 'DESC'});
+    #my $items = $c->model('polls')->select(limit => $limit + 1,
+    #                                       order_by => {create_time => 'DESC'});
+    my $items = $c->model_cache->select('polls', CACHE_SEC,
+                                        limit => $limit + 1,
+                                        order_by => {create_time => 'DESC'});
 
     $c->_render_timeline(items => $items,
                          limit => $limit,