7 #get_feeds_rating ( { offset => '', length => '', sort_by => '', search_name => '' } )
8 sub get_feeds_rating_segment
{
10 my $offset = $args->{"offset"} || 0;
11 my $length = $args->{"length"} || 5;
12 my $sort_by = $args->{"sort_by"} || "soccap";
14 ##### Search mode if set search_name parameter ####
16 my $search_name = $args->{"search_name"};
18 my $user = LJ
::load_user
($search_name);
19 $search_id = $user->id() if LJ
::isu
($user);
21 ###################################################
23 my @data = @
{_get_feeds_from_db
()};
24 my $total = scalar @data;
26 my @uids = map { $_->[0]} @data;
27 my $users = LJ
::User
->get_authority_multi( \
@uids );
29 $_->[3] = $users->{$_->[0]};
32 ###### by default values sorting by number of watchers, if we are need sorting by social capital then do it.
33 @data = reverse sort { $a->[3] <=> $b->[3] } @data if $sort_by eq "soccap";
39 position
=> $position,
40 journal_id
=> $_->[0],
47 ##### in search mode we are trying find needed position
48 if ( $_->{"journal_id"} == $search_id ) {
49 $search_res = $_->{"position"};
51 $offset = POSIX
::floor
( $search_res / $length ) * $length;
55 my @data = splice(@data, $offset, $length);
58 return { total
=> $total, data
=> $result, search_res
=> $search_res };
63 my $popsyn = LJ
::MemCache
::get
("popsyn");
65 $popsyn = _get_feeds_from_db
();
67 # load u objects so we can get usernames
69 LJ
::load_userids_multiple
([ map { $_, \
$users{$_} } map { $_->[0] } @
$popsyn ]);
70 unshift @
$_, $users{$_->[0]}->{'user'}, $users{$_->[0]}->{'name'} foreach @
$popsyn;
71 # format is: [ user, name, userid, synurl, numreaders ]
73 my $expire = time() + 3600; # 1 hour
74 LJ
::MemCache
::set
("popsyn", $popsyn, $expire);
79 sub get_popular_feed_ids
{
80 my $popsyn_ids = LJ
::MemCache
::get
("popsyn_ids");
81 unless ($popsyn_ids) {
82 my $popsyn = _get_feeds_from_db
();
83 @
$popsyn_ids = map { $_->[0] } @
$popsyn;
86 my $expire = time() + 3600; # 1 hour
87 LJ
::MemCache
::set
("popsyn_ids", $popsyn_ids, $expire);
92 sub _get_feeds_from_db
{
95 my $dbr = LJ
::get_db_reader
();
96 my $sth = $dbr->prepare("SELECT userid, synurl, numreaders FROM syndicated ".
97 "WHERE numreaders > 0 ".
98 "AND lastnew > DATE_SUB(NOW(), INTERVAL 14 DAY) ".
99 "ORDER BY numreaders DESC LIMIT 1000");
101 while (my @row = $sth->fetchrow_array) {
102 push @
$popsyn, [ @row ];