[dw-free] better organization of LJ functions
[commit: http://hg.dwscoalition.org/dw-free/rev/b9af037b2e58]
http://bugs.dwscoalition.org/show_bug.cgi?id=3965
Change LJ::note_recent_action to LJ::DB::note_recent_action. Involves a move
from ljlib.pl to LJ/DB.pm
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=3965
Change LJ::note_recent_action to LJ::DB::note_recent_action. Involves a move
from ljlib.pl to LJ/DB.pm
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/upgrading/base-data.sql
- cgi-bin/LJ/DB.pm
- cgi-bin/LJ/Sendmail.pm
- cgi-bin/ljlib.pl
-------------------------------------------------------------------------------- diff -r 984172d13ad7 -r b9af037b2e58 bin/upgrading/base-data.sql --- a/bin/upgrading/base-data.sql Thu Dec 01 15:53:52 2011 +0800 +++ b/bin/upgrading/base-data.sql Thu Dec 01 15:59:07 2011 +0800 @@ -772,7 +772,7 @@ REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Clustered. Stores ESN journal subscriptions data. A flag on event target (a journal) is written here saying whether there are known listeners out there.', '0', 'off', NULL, 'has_subs'); REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Clustered. Stores IP addresses for spam reports, temporarily, whether the journal in which the anonymous comment was posted in has enabled IP tracking or not. Used with the [dbtable[spamreports]] table.\n\r\nThe LJ::record_anon_comment_ip function gets the anonymous comment IP, and records it here.\r\n\r\nA maintenance task cleans out IPs after 5 days - so anonymous comments deleted after 5 days are fairly useless, and reports about them are quietly discarded by the comment deletion system.', '0', 'off', NULL, 'tempanonips'); REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Clustered. Stores Jabber roster data.', '0', 'off', NULL, 'jabroster'); -REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Clustered. Stores a log count of generic actions that have happened, like a post action (which calls LJ::note_recent_action()).\n\r\nA maintenance task moves these logged summaries from the various clusters to the global [dbtable[actionhistory]] table.', '0', 'off', NULL, 'recentactions'); +REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Clustered. Stores a log count of generic actions that have happened, like a post action (which calls LJ::DB::note_recent_action()).\n\r\nA maintenance task moves these logged summaries from the various clusters to the global [dbtable[actionhistory]] table.', '0', 'off', NULL, 'recentactions'); REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Clustered. Stores blobs (binary large objects) of on-disk data.\n\r\nBlob* files/classes for storing Blobs need to be added either to a local path or a remote Blob server (\"remote Blob server\" support has since been removed in favor of MogileFS).\r\n\r\nNotes: blobids aren\'t necessarily unique between domains; global userpicids may collide with the counter used for the rest. So, the type must be in the key. domain IDs are set up in etc/config.pl.', '0', 'off', NULL, 'userblob'); REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Clustered. Stores comments, such as OpenID comments, awaiting user approval.', '0', 'off', NULL, 'pendcomments'); REPLACE INTO schematables (des, public_browsable, redist_mode, redist_where, tablename) VALUES ('Clustered. Stores community invitations received.', '0', 'off', NULL, 'inviterecv'); diff -r 984172d13ad7 -r b9af037b2e58 cgi-bin/LJ/DB.pm --- a/cgi-bin/LJ/DB.pm Thu Dec 01 15:53:52 2011 +0800 +++ b/cgi-bin/LJ/DB.pm Thu Dec 01 15:59:07 2011 +0800 @@ -490,6 +490,31 @@ } +sub note_recent_action { + my ( $cid, $action ) = @_; + + # make sure they gave us an action (and it's not a long string) + return undef if ! $action || length( $action ) > 20; + + # fall back to selecting a random cluster if none specified + $cid = LJ::DB::random_cluster() unless defined $cid; + + # accept a user object + $cid = ref $cid ? $cid->{clusterid} + 0 : $cid + 0; + + return undef unless $cid; + + my $dbcm = LJ::get_cluster_master( $cid ) + or return undef; + + # append to recentactions table + $dbcm->do( "INSERT INTO recentactions VALUES (?)", undef, $action ); + return undef if $dbcm->err; + + return 1; +} + + package LJ; use Carp qw(confess); # import confess into package LJ diff -r 984172d13ad7 -r b9af037b2e58 cgi-bin/LJ/Sendmail.pm --- a/cgi-bin/LJ/Sendmail.pm Thu Dec 01 15:53:52 2011 +0800 +++ b/cgi-bin/LJ/Sendmail.pm Thu Dec 01 15:59:07 2011 +0800 @@ -162,7 +162,8 @@ # at this point $msg is a MIME::Lite # note that we sent an email - LJ::note_recent_action(undef, $msg->attr('content-type') =~ /plain/i ? 'email_send_text' : 'email_send_html'); + LJ::DB::note_recent_action( undef, $msg->attr('content-type') =~ /plain/i + ? 'email_send_text' : 'email_send_html' ); my $enqueue = sub { my $starttime = [gettimeofday()]; diff -r 984172d13ad7 -r b9af037b2e58 cgi-bin/ljlib.pl --- a/cgi-bin/ljlib.pl Thu Dec 01 15:53:52 2011 +0800 +++ b/cgi-bin/ljlib.pl Thu Dec 01 15:59:07 2011 +0800 @@ -1678,30 +1678,6 @@ } -sub note_recent_action { - my ($cid, $action) = @_; - - # fall back to selecting a random cluster - $cid = LJ::DB::random_cluster() unless defined $cid; - - # accept a user object - $cid = ref $cid ? $cid->{clusterid}+0 : $cid+0; - - return undef unless $cid; - - # make sure they gave us an action - return undef if !$action || length($action) > 20;; - - my $dbcm = LJ::get_cluster_master($cid) - or return undef; - - # append to recentactions table - $dbcm->do( "INSERT INTO recentactions VALUES (?)", undef, $action ); - return undef if $dbcm->err; - - return 1; -} - sub is_web_context { return $ENV{MOD_PERL} ? 1 : 0; } --------------------------------------------------------------------------------