fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-02-23 12:23 pm

[dw-free] Avoid reading page spam when creating feeds

[commit: http://hg.dwscoalition.org/dw-free/rev/e17770214bbf]

http://bugs.dwscoalition.org/show_bug.cgi?id=2369

Show only the last three entries from a newly created feed on your read
page. (The feed's recent entries page, and subsequent fetches, will not be
affected).

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/S2/RecentPage.pm
  • cgi-bin/LJ/SynSuck.pm
  • cgi-bin/ljprotocol.pl
--------------------------------------------------------------------------------
diff -r 741f3b446e9f -r e17770214bbf cgi-bin/LJ/S2/RecentPage.pm
--- a/cgi-bin/LJ/S2/RecentPage.pm	Wed Feb 23 17:01:48 2011 +0800
+++ b/cgi-bin/LJ/S2/RecentPage.pm	Wed Feb 23 20:23:30 2011 +0800
@@ -140,7 +140,7 @@ sub RecentPage
         security      => $opts->{securityfilter},
         itemids       => \@itemids,
         dateformat    => 'S2',
-        order         => ( $u->is_community || $u->is_syndicated ) ? 'logtime' : '',
+        order         => $u->is_community ? 'logtime' : '',
         err           => \$err,
         posterid      => $posteru_filter ? $posteru_filter->id : undef,
     );
diff -r 741f3b446e9f -r e17770214bbf cgi-bin/LJ/SynSuck.pm
--- a/cgi-bin/LJ/SynSuck.pm	Wed Feb 23 17:01:48 2011 +0800
+++ b/cgi-bin/LJ/SynSuck.pm	Wed Feb 23 20:23:30 2011 +0800
@@ -291,7 +291,9 @@ sub process_content {
     }
 
     # post these items
-    my $newcount = 0;
+    my $itemcount = scalar @items;
+    my $newfeed   = ! $su->timeupdate;  # true if never updated before
+    my $newcount  = 0;
     my $errorflag = 0;
     my $mindate;  # "yyyy-mm-dd hh:mm:ss";
     my $notedate = sub {
@@ -310,12 +312,14 @@ sub process_content {
             $it->{$attr} = LJ::no_utf8_flag ( $it->{$attr} );
         }
 
+        # duplicate entry detection
         my $dig = LJ::md5_struct($it)->b64digest;
         my $prevadd = $dbh->selectrow_array("SELECT MAX(dateadd) FROM synitem WHERE ".
                                             "userid=? AND item=?", undef,
                                             $userid, $dig);
         if ($prevadd) {
             $notedate->($prevadd);
+            $itemcount--;
             next;
         }
 
@@ -326,7 +330,6 @@ sub process_content {
                  undef, $userid, $dig, $now_dateadd);
         $notedate->($now_dateadd);
 
-        $newcount++;
         print "[$$] $dig - $it->{'subject'}\n" if $verbose;
         $it->{'text'} =~ s/^\s+//;
         $it->{'text'} =~ s/\s+$//;
@@ -378,8 +381,13 @@ sub process_content {
         # just bail on entries older than two weeks instead of reposting them
         if ($own_time) {
             my $age = time() - LJ::mysqldate_to_time($it->{'time'});
-            next if $age > $secs; # $secs is defined waaaaaaaay above
+            if ( $age > $secs ) {  # $secs is defined waaaaaaaay above
+                $itemcount--;
+                next;
+            }
         }
+
+        $newcount++;  # we're committed to posting this item now
 
         my $command = "postevent";
         my $req = {
@@ -407,6 +415,13 @@ sub process_content {
         if ($it->{'text'} =~ /<(?:p|br)\b/i) {
             $req->{'props'}->{'opt_preformatted'} = 1;
         }
+
+        # If this is a new feed, backdate all but last three items.
+        # Note this is a best effort; might not print all three entries
+        # if duplicate entries are detected later in the feed.
+
+        $req->{props}->{opt_backdated} = 1
+            if $newfeed && ( $itemcount - $newcount ) >= 3;
 
         # do an editevent if we've seen this item before
         my $id = $have_ids ? $it->{'id'} : $it->{'link'};
diff -r 741f3b446e9f -r e17770214bbf cgi-bin/ljprotocol.pl
--- a/cgi-bin/ljprotocol.pl	Wed Feb 23 17:01:48 2011 +0800
+++ b/cgi-bin/ljprotocol.pl	Wed Feb 23 20:23:30 2011 +0800
@@ -1318,7 +1318,7 @@ sub postevent
     # don't allow backdated posts in communities
     return fail($err,152) if
         ( $req->{props}->{opt_backdated} &&
-         ! ( $importer_bypass || $uowner->is_person ) );
+         ! $importer_bypass && $uowner->is_community );
 
     # do processing of embedded polls (doesn't add to database, just
     # does validity checking)
@@ -1885,8 +1885,7 @@ sub editevent
 
     # don't allow backdated posts in communities
     return fail($err,152) if
-        ($req->{'props'}->{"opt_backdated"} &&
-         ! $uowner->is_person);
+        $req->{props}->{opt_backdated} && $uowner->is_community;
 
     # make year/mon/day/hour/min optional in an edit event,
     # and just inherit their old values
--------------------------------------------------------------------------------
ninetydegrees: Art & Text: heart with aroace colors, "you are loved" (Default)

[personal profile] ninetydegrees 2011-02-23 04:26 pm (UTC)(link)
Yay!
silverflight8: Different shades of blue flowing on a white background like waves (Fractal)

[personal profile] silverflight8 2011-02-23 10:56 pm (UTC)(link)
Hooray! This is really exciting.