[dw-free] need "moderation queue" function
[commit: http://hg.dwscoalition.org/dw-free/rev/d1cdcb5897f7]
http://bugs.dwscoalition.org/show_bug.cgi?id=1457
Add moderation queue function (refactoring, plus error checking, plus
memcache, to make it more robust and in preparation for using the mod queue
count on higher-traffic pages)
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1457
Add moderation queue function (refactoring, plus error checking, plus
memcache, to make it more robust and in preparation for using the mod queue
count on higher-traffic pages)
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- cgi-bin/communitylib.pl
- cgi-bin/ljprotocol.pl
- htdocs/community/manage.bml
- htdocs/community/moderate.bml
-------------------------------------------------------------------------------- diff -r 25e3ab947afe -r d1cdcb5897f7 cgi-bin/communitylib.pl --- a/cgi-bin/communitylib.pl Sun Jul 26 00:32:30 2009 -0500 +++ b/cgi-bin/communitylib.pl Sun Jul 26 17:47:31 2009 +0000 @@ -634,5 +634,22 @@ sub set_comm_settings { return; } +sub get_mod_queue_count { + my $cu = LJ::want_user( shift ); + return 0 unless $cu->is_community; + + my $mqcount = $cu->memc_get( 'mqcount' ); + return $mqcount if defined $mqcount; + + # if it's not in memcache, hit the db + my $dbr = LJ::get_cluster_reader( $cu ); + my $sql = "SELECT COUNT(*) FROM modlog WHERE journalid=" . $cu->id; + $mqcount = $dbr->selectrow_array( $sql ) || 0; + + # store in memcache for 10 minutes + $cu->memc_set( 'mqcount' => $mqcount, 600 ); + return $mqcount; +} + + 1; - diff -r 25e3ab947afe -r d1cdcb5897f7 cgi-bin/ljprotocol.pl --- a/cgi-bin/ljprotocol.pl Sun Jul 26 00:32:30 2009 -0500 +++ b/cgi-bin/ljprotocol.pl Sun Jul 26 17:47:31 2009 +0000 @@ -1277,6 +1277,9 @@ sub postevent $uowner->do("DELETE FROM modlog WHERE journalid=$ownerid AND modid=$modid"); return fail($err, 501); } + + # expire mod_queue_count memcache + $uowner->memc_delete( 'mqcount' ); # alert moderator(s) my $mods = LJ::load_rel_user($dbh, $ownerid, 'M') || []; diff -r 25e3ab947afe -r d1cdcb5897f7 htdocs/community/manage.bml --- a/htdocs/community/manage.bml Sun Jul 26 00:32:30 2009 -0500 +++ b/htdocs/community/manage.bml Sun Jul 26 17:47:31 2009 +0000 @@ -47,15 +47,12 @@ body<= my $sth = $dbr->prepare("SELECT userid, membership FROM community ". "WHERE userid IN ($in)"); $sth->execute; - my $udbr; while (my ($uid, $membership) = $sth->fetchrow_array) { my $cu = $us->{$uid}; next unless $cu && $cu->{statusvis} eq "V" || $cu->is_readonly; $names{$uid} = [ $cu->{user}, $cu->{name}, -1 ]; if ($mods{$uid}) { - $udbr = LJ::get_cluster_reader($cu); - my $sql = "SELECT COUNT(*) FROM modlog WHERE journalid=$uid"; - $modcount{$uid} = $names{$uid}[2] = $udbr->selectrow_array($sql) || 0; + $modcount{$uid} = $names{$uid}[2] = LJ::get_mod_queue_count( $uid ); } if ($membership eq 'moderated') { my $ids = LJ::get_pending_members($uid) || []; diff -r 25e3ab947afe -r d1cdcb5897f7 htdocs/community/moderate.bml --- a/htdocs/community/moderate.bml Sun Jul 26 00:32:30 2009 -0500 +++ b/htdocs/community/moderate.bml Sun Jul 26 17:47:31 2009 +0000 @@ -163,6 +163,9 @@ body<= undef, $c->{'userid'}, $modid); $c->do("DELETE FROM modblob WHERE journalid=? AND modid=?", undef, $c->{'userid'}, $modid); + + # expire mod_queue_count memcache + $c->memc_delete( 'mqcount' ); # FALL THROUGH to showing the list of entries in this community } else { --------------------------------------------------------------------------------