vadvs (vadvs) wrote in changelog,
vadvs
vadvs
changelog

[livejournal] r15178: LJLMI-7:

Committer: vad
LJLMI-7:
add 'friend_history' table.
add record to 'friend_history' when user add friend
some changes in settings.css

U   branches/msn/bin/upgrading/update-db-general.pl
A   branches/msn/cgi-bin/LJ/RateLimit.pm
U   branches/msn/cgi-bin/LJ/User.pm
U   branches/msn/cgi-bin/ljprotocol.pl
U   branches/msn/cgi-bin/talklib.pl
U   branches/msn/htdocs/stc/settings.css
Modified: branches/msn/bin/upgrading/update-db-general.pl
===================================================================
--- branches/msn/bin/upgrading/update-db-general.pl	2009-05-15 03:55:03 UTC (rev 15177)
+++ branches/msn/bin/upgrading/update-db-general.pl	2009-05-15 06:49:22 UTC (rev 15178)
@@ -3121,7 +3121,19 @@
 )
 EOC
 
+register_tablecreate("friend_history", <<'EOC');
+CREATE TABLE friend_history (
+    rec_id  INT UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
+    action  VARCHAR(23),
+    uid     INT(10) UNSIGNED NOT NULL,
+    fid     INT(10) UNSIGNED NOT NULL,
+    status  INT(10),
+    added   DATETIME,
+    INDEX(action)
+)                           
+EOC
 
+
 ### changes
 
 register_alter(sub {

Added: branches/msn/cgi-bin/LJ/RateLimit.pm
===================================================================
--- branches/msn/cgi-bin/LJ/RateLimit.pm	                        (rev 0)
+++ branches/msn/cgi-bin/LJ/RateLimit.pm	2009-05-15 06:49:22 UTC (rev 15178)
@@ -0,0 +1,77 @@
+package LJ::RateLimit;
+use strict;
+use LJ::MemCache qw//;
+
+our $RATE_DATAVER = 1;
+
+
+# more anti-spammer rate limiting.  returns 1 if rate is okay, 0 if too fast.
+#
+# args:
+#   1) u -> user that performs action
+#   2) rate conditions
+#      [
+#       [ memcache key, [ [rate, period-of-time], [rate, period-of-time] ],
+#       ...
+#      ]
+#           
+sub check {
+    my $class = shift;
+    my $u     = shift;
+    my @watch = @{ shift || [] };
+
+    # we require memcache to do rate limiting efficiently
+    return 1 unless @LJ::MEMCACHE_SERVERS;
+
+    # return right away if the account is suspended
+    return 0 if $u && $u->statusvis =~ /[SD]/;
+
+    # allow some users to be very aggressive commenters and authors. i.e. our bots.
+    return 1 if $u
+                and grep { $u->username eq $_ } @LJ::NO_RATE_CHECK_USERS;
+
+
+    my $ip  = LJ::get_remote_ip();
+    my $now = time();
+    foreach my $watch (@watch) {
+        my ($key, $rates) = ($watch->[0], $watch->[1]);
+        my $max_period = $rates->[0]->[1];
+
+        my $log = LJ::MemCache::get($key);
+
+        # parse the old log
+        my @times = ();
+        if (length($log) % 4 == 1 && substr($log,0,1) eq $RATE_DATAVER) {
+            my $ct = (length($log)-1) / 4;
+            for (my $i=0; $i<$ct; $i++) {
+                my $time = unpack("N", substr($log,$i*4+1,4));
+                push @times, $time if $time > $now - $max_period;
+            }
+        }
+
+        # add this event unless we're throttling based on spamreports
+        push @times, $now unless $key =~ /^spamreports/;
+
+        # check rates
+        foreach my $rate (@$rates) {
+            my ($allowed, $period) = ($rate->[0], $rate->[1]);
+            my $events = scalar grep { $_ > $now-$period } @times;
+
+            return 0 # RATE LIMIT EXCEEDED
+                if $events > $allowed;
+        }
+
+        # build the new log
+        my $newlog = $RATE_DATAVER;
+        foreach (@times) {
+            $newlog .= pack("N", $_);
+        }
+        LJ::MemCache::set($key, $newlog, $max_period);
+    }
+
+    return 1;
+}
+
+
+1;
+

Modified: branches/msn/cgi-bin/LJ/User.pm
===================================================================
--- branches/msn/cgi-bin/LJ/User.pm	2009-05-15 03:55:03 UTC (rev 15177)
+++ branches/msn/cgi-bin/LJ/User.pm	2009-05-15 06:49:22 UTC (rev 15178)
@@ -20,6 +20,7 @@
 use LJ::Constants;
 use LJ::MemCache;
 use LJ::Session;
+use LJ::RateLimit qw//;
 use URI qw//;
 
 use Class::Autouse qw(
@@ -3944,6 +3945,9 @@
     my $u = shift;
     my @friendids = $u->friend_uids;
     my $users = LJ::load_userids(@friendids);
+    while(my ($uid, $u) = each %$users){
+        delete $users->{$uid} unless $u;
+    }
     return values %$users if wantarray;
     return $users;
 }
@@ -6723,7 +6727,7 @@
 sub set_interests
 {
     my ($u, $old, $new) = @_;
-
+    
     $u = LJ::want_user($u);
     my $userid = $u->{'userid'};
     return undef unless $userid;
@@ -6917,7 +6921,7 @@
         my $sth = $dbh->prepare("SELECT intid FROM $uitable WHERE userid=?");
         $sth->execute($uid);
         push @$ids, $_ while ($_) = $sth->fetchrow_array;
-        LJ::MemCache::add($mk_ids, $ids, 3600*12);
+        LJ::MemCache::add($mk_ids, $ids);
     }
 
     # FIXME: set a 'justids' $u cache key in this case, then only return that 
@@ -7262,8 +7266,19 @@
     my @add_ids = ref $to_add eq 'ARRAY' ? map { LJ::want_userid($_) } @$to_add : ( LJ::want_userid($to_add) );
     return 0 unless @add_ids;
 
-    my $dbh = LJ::get_db_writer();
+    my $friender = LJ::load_userid($userid);
+    
+    # check action rate
+    unless ($opts->{no_rate_check}){
+        my $cond = ["ratecheck:add_friend:$userid", 
+                    [ $LJ::ADD_FRIEND_RATE_LIMIT || [ 1, 3600 ] ] 
+                   ];
+        return 0 unless LJ::RateLimit->check($friender, [ $cond ]);
+    }
 
+    my $dbh      = LJ::get_db_writer();
+    my $sclient  = LJ::theschwartz();
+
     my $fgcol = LJ::color_todb($opts->{'fgcolor'}) || LJ::color_todb("#000000");
     my $bgcol = LJ::color_todb($opts->{'bgcolor'});
     # in case the background color is #000000, in which case the || falls through
@@ -7289,9 +7304,6 @@
     my $res = LJ::_friends_do
         ($userid, "REPLACE INTO friends (userid, friendid, fgcolor, bgcolor, groupmask) VALUES $bind", @vals);
 
-    my $sclient = LJ::theschwartz();
-    my $friender = LJ::load_userid($userid);
-
     # part of the criteria for whether to fire befriended event
     my $notify = !$LJ::DISABLED{esn} && !$opts->{nonotify}
                  && $friender->is_visible && $friender->is_person;

Modified: branches/msn/cgi-bin/ljprotocol.pl
===================================================================
--- branches/msn/cgi-bin/ljprotocol.pl	2009-05-15 03:55:03 UTC (rev 15177)
+++ branches/msn/cgi-bin/ljprotocol.pl	2009-05-15 06:49:22 UTC (rev 15178)
@@ -16,6 +16,8 @@
                       LJ::EventLogRecord::EditEntry
                       LJ::Config
                       LJ::Comment
+                      LJ::Friend::History
+                      LJ::RateLimit
                       );
 
 LJ::Config->load;
@@ -109,6 +111,7 @@
      "408" => [ E_TEMP, "Maximum queued posts for this community+poster combination reached." ],
      "409" => [ E_PERM, "Post too large." ],
      "410" => [ E_PERM, "Your trial account has expired.  Posting now disabled." ],
+     "411" => [ E_TEMP, "Action frequency limit." ],
 
      # Server Errors
      "500" => [ E_TEMP, "Internal server error" ],
@@ -2285,6 +2288,18 @@
     # do not let locked people do this
     return fail($err, 308) if $u->{statusvis} eq 'L';
 
+#
+# Do not have values for $LJ::ADD_FRIEND_RATE_LIMIT
+# 
+#    # check action frequency
+#    unless ($flags->{no_rate_check}){
+#        my $cond = ["ratecheck:add_friend:$userid",
+#                    [ $LJ::ADD_FRIEND_RATE_LIMIT || [ 10, 600 ] ]
+#                   ];
+#        return fail($err, 411)
+#            unless LJ::RateLimit->check($u, [ $cond ]);
+#    }
+
     my $res = {};
 
     ## first, figure out who the current friends are to save us work later
@@ -2419,8 +2434,15 @@
                                                   funcname => "LJ::Worker::FriendChange",
                                                   arg      => [$userid, 'add', $friendid],
                                                   ) unless $LJ::DISABLED{'friendchange-schwartz'};
-
+                
                 $sclient->insert_jobs(@jobs) if @jobs;
+                
+                # log action
+                LJ::Friend::History->add_record(
+                    action => "friended",
+                    uid    => $userid,
+                    fid    => $friendid,
+                    );
             }
 
             LJ::run_hooks('befriended', LJ::load_userid($userid), LJ::load_userid($friendid));

Modified: branches/msn/cgi-bin/talklib.pl
===================================================================
--- branches/msn/cgi-bin/talklib.pl	2009-05-15 03:55:03 UTC (rev 15177)
+++ branches/msn/cgi-bin/talklib.pl	2009-05-15 06:49:22 UTC (rev 15178)
@@ -11,6 +11,7 @@
 package LJ::Talk;
 
 use LJ::Constants;
+use LJ::RateLimit qw//;
 use Class::Autouse qw(
                       LJ::Event::JournalNewComment
                       LJ::Event::UserNewComment
@@ -3520,21 +3521,10 @@
 # more anti-spammer rate limiting.  returns 1 if rate is okay, 0 if too fast.
 sub check_rate {
     my ($remote, $journalu) = @_;
+    return 1 unless $LJ::ANTI_TALKSPAM;
 
-    # we require memcache to do rate limiting efficiently
-    return 1 unless @LJ::MEMCACHE_SERVERS;
-
-    # return right away if the account is suspended
-    return 0 if $remote && $remote->{'statusvis'} =~ /[SD]/;
-
-    # allow some users to be very aggressive commenters and authors. i.e. our bots.
-    return 1 if $remote
-                and grep { $remote->username eq $_ } @LJ::NO_RATE_CHECK_USERS;
-
-
     my $ip = LJ::get_remote_ip();
-    my $now = time();
-    my @watch;
+    my @watch = ();
 
     if ($remote) {
         # registered human (or human-impersonating robot)
@@ -3571,72 +3561,7 @@
           ];
     }
 
-
-  WATCH:
-    foreach my $watch (@watch) {
-        my ($key, $rates) = ($watch->[0], $watch->[1]);
-        my $max_period = $rates->[0]->[1];
-
-        my $log = LJ::MemCache::get($key);
-
-        # parse the old log
-        my @times;
-        if (length($log) % 4 == 1 && substr($log,0,1) eq $RATE_DATAVER) {
-            my $ct = (length($log)-1) / 4;
-            for (my $i=0; $i<$ct; $i++) {
-                my $time = unpack("N", substr($log,$i*4+1,4));
-                push @times, $time if $time > $now - $max_period;
-            }
-        }
-
-        # add this event unless we're throttling based on spamreports
-        push @times, $now unless $key =~ /^spamreports/;
-
-        # check rates
-        foreach my $rate (@$rates) {
-            my ($allowed, $period) = ($rate->[0], $rate->[1]);
-            my $events = scalar grep { $_ > $now-$period } @times;
-            if ($events > $allowed) {
-
-                if ($LJ::DEBUG{'talkrate'} &&
-                    LJ::MemCache::add("warn:$key", 1, 600)) {
-
-                    my $ruser = (exists $remote->{'user'}) ? $remote->{'user'} : 'Not logged in';
-                    my $nowtime = localtime($now);
-                    my $body = <<EOM;
-Talk spam from $key:
-$events comments > $allowed allowed / $period secs
-     Remote user: $ruser
-     Remote IP:   $ip
-     Time caught: $nowtime
-     Posting to:  $journalu->{'user'}
-EOM
-
-                        LJ::send_mail({
-                            'to' => $LJ::DEBUG{'talkrate'},
-                            'from' => $LJ::ADMIN_EMAIL,
-                            'fromname' => $LJ::SITENAME,
-                            'charset' => 'utf-8',
-                            'subject' => "talk spam: $key",
-                            'body' => $body,
-                        });
-                } # end sending email
-
-                return 0 if $LJ::ANTI_TALKSPAM;
-                last WATCH;
-            }
-        }
-
-        # build the new log
-        my $newlog = $RATE_DATAVER;
-        foreach (@times) {
-            $newlog .= pack("N", $_);
-        }
-
-        LJ::MemCache::set($key, $newlog, $max_period);
-    }
-
-    return 1;
+    return LJ::RateLimit->check($remote, \@watch);
 }
 
 1;

Modified: branches/msn/htdocs/stc/settings.css
===================================================================
--- branches/msn/htdocs/stc/settings.css	2009-05-15 03:55:03 UTC (rev 15177)
+++ branches/msn/htdocs/stc/settings.css	2009-05-15 06:49:22 UTC (rev 15178)
@@ -154,6 +154,10 @@
 	border-collapse: collapse;
 }
 
+.integration TD.inprogr {
+	border: none;
+}
+
 .integration td.integration_label {
 	width: 12em;
 	vertical-align: top;
@@ -171,10 +175,16 @@
 	overflow: hidden;
 }
 .integration SPAN.comment {
-	font-size: .85em;
+	/*font-size: .85em;*/
 	color: #999;
-	margin-left: 25px;
+	margin-left: 5px;
 }
+
+.integration SPAN.msn-inprogr {
+	display: inline;
+	color:#336699;
+}
+
 .integration .disabled_msn SPAN.comment {
 	color:#b2b2b2;
 }
@@ -184,6 +194,12 @@
 	top: -2px;
 	float: left;
 }
+.integration  span #msnc1, .integration span #msnc2 {
+	top: -1px;
+	left: -1px;
+	margin-bottom: 3px;
+}
+
 .integration span LABEL {
 	float: left;
 	height: 1%;

Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments