1 package Gruta
::Source
::BASE
;
11 $self->{data
} = shift;
20 if (!exists $self->data->{args
}->{dummy_touch
}) {
22 my $t = $self->template('cfg_top_ten_num');
24 if ($t && $t->get('content') <= 0) {
28 $self->data->{args
}->{dummy_touch
} = $r;
31 return $self->data->{args
}->{dummy_touch
};
41 if (!$self->{story_cache
}) {
42 $self->{story_cache
} = {};
45 my $ck = $topic_id . '/' . $id;
48 $self->{story_cache
}->{$ck} = $story;
51 $story = $self->{story_cache
}->{$ck};
66 my @tags = $story->tags();
68 my $id = $story->get('id');
69 my $topic_id = $story->get('topic_id');
76 # mark the current story as already used
77 $h{$topic_id . '/' . $id} = 1;
79 foreach my $i ($self->stories_by_tag(undef, join(",", @tags))) {
80 my $k = $i->[0] . '/' . $i->[1];
90 @ret1 = sort { $b->[2] cmp $a->[2] } @ret1;
92 # if not enough, get others, tag by tag
93 if (scalar(@ret1) < $max) {
94 while (scalar(@tags)) {
95 foreach my $i ($self->stories_by_tag(undef, shift(@tags))) {
96 my $k = $i->[0] . '/' . $i->[1];
108 @ret2 = sort { $b->[2] cmp $a->[2] } @ret2;
110 @ret = (@ret1, @ret2);
113 return scalar(@ret) > $max ?
@ret[0 .. ($max - 1)] : @ret;