From 2eea149793bd3745e6f2ead802f294b1be537e87 Mon Sep 17 00:00:00 2001 From: hylom Date: Tue, 4 Jul 2017 22:13:46 +0900 Subject: [PATCH] * Model::Stories: remove _latest() --- src/newslash_web/lib/Newslash/Model/Stories.pm | 109 ------------------------- 1 file changed, 109 deletions(-) diff --git a/src/newslash_web/lib/Newslash/Model/Stories.pm b/src/newslash_web/lib/Newslash/Model/Stories.pm index 749e36e5..5fe4ebe7 100644 --- a/src/newslash_web/lib/Newslash/Model/Stories.pm +++ b/src/newslash_web/lib/Newslash/Model/Stories.pm @@ -9,115 +9,6 @@ use Data::Dumper; use DateTime; use Newslash::Util::Formatters qw(datetime_to_string); -#======================================================================== - -=head2 latest(\%options) - -get latest stories. - -=over 4 - -=item Parameters - -=over 4 - -=item \%options - -options for query. - -$options->{show_future}: when 1, return feature stories. default is 0. -$options->{limit}: number of stories. default is 10. - -=back - -=item Return value - -ARRAY of story contents - -=back - -=cut - -sub _latest { - my $self = shift; - my $options = {}; - if (@_ > 0) { - if (ref($_[0]) eq 'HASH') { - $options = shift; - } - else { - $options = {@_}; - } - } - - my $show_future = $options->{show_future} || 0; - my $limit = $options->{limit} || 10; - - my $dbh = $self->connect_db; - - # get stories - my $where_clause = 'WHERE stories.time <= NOW()';; - if ($show_future) { - $where_clause = ''; - } - - my $sql = <<"EOSQL"; -SELECT latest.*, story_text.*, users.nickname AS author, firehose.public - FROM (SELECT * from stories $where_clause ORDER BY time DESC LIMIT ?) AS latest - LEFT JOIN story_text ON latest.stoid = story_text.stoid - LEFT JOIN users ON latest.uid = users.uid - LEFT JOIN firehose - ON (stories.stoid = firehose.srcid AND firehose.type = "story") -EOSQL - - my $sth = $dbh->prepare($sql); - - $sth->execute($limit); - my $rs = $sth->fetchall_arrayref(+{}); - - if (@$rs == 0) { - $self->disconnect_db(); - return []; - } - - # get tags - $sql = <<"EOSQL"; -SELECT story_topics_rendered.*, story_topics_chosen.weight, topics.* - FROM (SELECT stoid FROM stories $where_clause ORDER BY time DESC LIMIT ?) AS latest - INNER JOIN story_topics_rendered ON latest.stoid = story_topics_rendered.stoid - LEFT JOIN story_topics_chosen ON story_topics_rendered.stoid = story_topics_chosen.stoid - AND story_topics_rendered.tid = story_topics_chosen.tid - LEFT JOIN topics ON story_topics_rendered.tid = topics.tid -EOSQL - - $sth = $dbh->prepare($sql); - - $sth->execute($limit); - my $topics_table = $sth->fetchall_arrayref(+{}); - $sth->finish; - $self->disconnect_db(); - - my $topics = {}; - for my $topic (@$topics_table) { - if (!$topic->{stoid}) { - $topics->{$topic->{stoid}} = []; - } - push @{$topics->{$topic->{stoid}}}, $topic; - } - - for my $story (@$rs) { - my $stoid = $story->{stoid}; - if ($stoid) { - $story->{topics} = $topics->{$stoid}; - } - $self->_generalize($story); - } - - return $rs; -} - - - sub _calculate_time_range { my ($self, $params) = @_; -- 2.11.0