LJSUP-17669: Login.bml form refactoring
[livejournal.git] / cgi-bin / LJ / Stats.pm
blob5dfd89b8992b3d8a158d9448a49657ec232241ce
1 # This is a module for returning stats info
2 # Functions in statslib.pl should get moved here
4 use strict;
6 package LJ::Stats;
8 use LJ::Faq;
9 use LJ::Lang;
11 sub get_popular_interests {
12 my $memkey = 'pop_interests';
13 my $ints;
15 # Try to fetch from memcache
16 my $mem = LJ::MemCache::get($memkey);
17 if ($mem) {
18 $ints = $mem;
19 return $ints;
22 # Fetch from database
23 my $dbr = LJ::get_db_reader();
24 $ints
25 = $dbr->selectall_arrayref(
26 "SELECT statkey, statval FROM stats WHERE " . "statcat=? ORDER BY statval DESC, statkey ASC",
27 undef, 'pop_interests' );
28 return undef if $dbr->err;
30 # update memcache
31 my $rv = LJ::MemCache::set( $memkey, \@$ints, 3600 );
33 return $ints;
36 sub get_popular_faq {
37 my ($user, $user_url) = @_;
39 my $dbr = LJ::get_db_reader();
40 my $rows
41 = $dbr->selectall_arrayref( "SELECT statkey FROM stats WHERE statcat='pop_faq' ORDER BY statval DESC LIMIT 10",
42 { Slice => {} } );
44 my $faq;
46 foreach my $r (@$rows) {
47 my $f = LJ::Faq->load( $r->{statkey}, 'lang' => LJ::Lang::current_language() );
48 $f->render_in_place( { user => $user, url => $user_url } );
49 my $q = $f->question_html;
50 my $link = $f->page_url;
51 push @$faq, { link => $link, question => $q };
54 return $faq;