madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r20100: LJSUP-9848: s2 pagins fixed

Committer: sbelyaev
LJSUP-9848: s2 pagins fixed
U   branches/delayed_entries/cgi-bin/LJ/DelayedEntry.pm
U   branches/delayed_entries/cgi-bin/LJ/S2/RecentPage.pm
Modified: branches/delayed_entries/cgi-bin/LJ/DelayedEntry.pm
===================================================================
--- branches/delayed_entries/cgi-bin/LJ/DelayedEntry.pm	2011-09-21 07:15:45 UTC (rev 20099)
+++ branches/delayed_entries/cgi-bin/LJ/DelayedEntry.pm	2011-09-21 08:38:18 UTC (rev 20100)
@@ -772,7 +772,6 @@
                                                      $u );
     }
 
-
     my $secwhere = __delayed_entry_secwhere( $journal,
                                              $journal->userid,
                                              $userid );
@@ -967,11 +966,15 @@
     return @items;
 }
 
-sub get_itemid_after2  { return get_itemid_near2(@_, "after");  }
-sub get_itemid_before2 { return get_itemid_near2(@_, "before"); }
+sub get_itemid_after2  {
+    return get_itemid_near2(@_, "after");
+}
 
-sub get_itemid_near2
-{
+sub get_itemid_before2 {
+    return get_itemid_near2(@_, "before");
+}
+
+sub get_itemid_near2{
     my ($self, $after_before) = @_;
     my $u = $self->journal;
     my $delayedid = $self->delayedid;
@@ -1082,55 +1085,58 @@
     my $poster     = $self->poster;
     my $posterid   = $poster->userid;
 
-    my $dbh = LJ::get_db_writer();
+    my $dbh  = LJ::get_db_writer();
     my $dbcm = LJ::get_cluster_master($journal);
 
     my $ext = $req->{data_d_ext};
 
-    my $flags       = $ext->{flags};
-    my $event       = $req->{event};
-    my $eventtime   = __get_datatime($req);
+    my $flags     = $ext->{flags};
+    my $event     = $req->{event};
+    my $eventtime = __get_datatime($req);
 
-    my $security = "public";
+    my $security  = "public";
     my $uselogsec = 0;
+
     if ($req->{'security'} eq "usemask" || $req->{'security'} eq "private") {
         $security = $req->{'security'};
     }
+
     if ($req->{'security'} eq "usemask") {
         $uselogsec = 1;
     }
 
-    my $qsecurity   = $dbh->quote($security);
-    my $qallowmask  = $req->{'allowmask'}+0;
-    my $qeventtime  = $dbh->quote($eventtime);
-    my $now         = $dbcm->selectrow_array("SELECT UNIX_TIMESTAMP()");
-    my $anum        = int(rand(256));
-    my $jitemid     = LJ::alloc_user_counter($journal, "L");
-    my $rlogtime    = $LJ::EndOfTime;
+    my $qsecurity  = $dbh->quote($security);
+    my $qallowmask = $req->{'allowmask'}+0;
+    my $qeventtime = $dbh->quote($eventtime);
+    my $now        = $dbcm->selectrow_array("SELECT UNIX_TIMESTAMP()");
+    my $anum       = int(rand(256));
+    my $jitemid    = LJ::alloc_user_counter($journal, "L");
+    my $rlogtime   = $LJ::EndOfTime;
 
     # do processing of embedded polls (doesn't add to database, just
     # does validity checking)
     my @polls = ();
-    if (LJ::Poll->contains_new_poll(\$event))
-    {
+
+    if (LJ::Poll->contains_new_poll(\$event)) {
         return "Your account type doesn't permit creating polls."
-        unless (LJ::get_cap($poster, "makepoll")
-        || ($journal->{'journaltype'} eq "C"
-        && LJ::get_cap($journal, "makepoll")
-        && LJ::can_manage_other($poster, $journal)));
+            unless (LJ::get_cap($poster, "makepoll")
+                    || ($journal->{'journaltype'} eq "C"
+                    && LJ::get_cap($journal, "makepoll")
+                    && LJ::can_manage_other($poster, $journal)));
 
         my $error = "";
         @polls = LJ::Poll->new_from_html(\$event, \$error, {
             'journalid' => $journalid,
             'posterid' => $posterid,
         });
+
         return $error if $error;
     }
 
-    $req->{subject} = $req->{subject} || '';
+    $req->{subject}    = $req->{subject} || '';
     $req->{usejournal} = $req->{usejournal} || '';
-    $req->{allowmask} = $req->{allowmask} || '';
-    $req->{security} = $req->{security} || '';
+    $req->{allowmask}  = $req->{allowmask} || '';
+    $req->{security}   = $req->{security} || '';
 
     my $dupsig = Digest::MD5::md5_hex(join('', map { $req->{$_} }
                             qw(subject event usejournal security allowmask)));
@@ -1148,19 +1154,30 @@
 
     my $getlock = sub {
         my $r = $dbcm->selectrow_array("SELECT GET_LOCK(?, 2)", undef, $lock_key);
+
         unless ($r) {
             $res = undef;    # a failure case has an undef result
             $res_done = 1;   # tell caller to bail out
-            return { error_message =>  "can't get lock", delete_entry => 0 } 
+
+            return {
+                error_message => "can't get lock",
+                delete_entry  => 0,
+            }; 
         }
+
         my @parts = split(/:/, $poster->{'dupsig_post'});
+
         if ($parts[0] eq $dupsig) {
             # duplicate!  let's make the client think this was just the
             # normal first response.
             $res->{'itemid'} = $parts[1];
-            $res->{'anum'} = $parts[2];
+            $res->{'anum'}   = $parts[2];
             
-            my $dup_entry = LJ::Entry->new($journal, jitemid => $res->{'itemid'}, anum => $res->{'anum'});
+            my $dup_entry = LJ::Entry->new(
+                $journal,
+                jitemid => $res->{'itemid'},
+                anum    => $res->{'anum'},
+            );
             $res->{'url'} = $dup_entry->url;
             
             $res_done = 1;
@@ -1183,7 +1200,10 @@
                                 "0, $req->{'year'}, $req->{'mon'}, $req->{'day'}, $LJ::EndOfTime-".
                                 "UNIX_TIMESTAMP($qeventtime), $rlogtime, $anum)");
 
-    return { error_message =>  $dberr, delete_entry => 0 } if $dberr;
+    return {
+        error_message => $dberr,
+        delete_entry  => 0,
+    } if $dberr;
 
     # post become 'sticky post'
     if ( $req->{type} && $req->{type} eq 'sticky' ) {

Modified: branches/delayed_entries/cgi-bin/LJ/S2/RecentPage.pm
===================================================================
--- branches/delayed_entries/cgi-bin/LJ/S2/RecentPage.pm	2011-09-21 07:15:45 UTC (rev 20099)
+++ branches/delayed_entries/cgi-bin/LJ/S2/RecentPage.pm	2011-09-21 08:38:18 UTC (rev 20100)
@@ -72,18 +72,32 @@
     }
 
     my $delayed_entries = [];
+    my $delayed_entries_count = LJ::DelayedEntry->get_entries_count($u);
+    my $usual_skip = $delayed_entries_count ? $skip - $delayed_entries_count : 0;
 
-    if ($u->has_sticky_entry && !$skip) {
-        $delayed_entries = LJ::DelayedEntry->get_entries_by_journal($u, $skip, $itemshow - 1) || [];
+    if ( $u->has_sticky_entry && !$skip) {
+        $delayed_entries = LJ::DelayedEntry->get_entries_by_journal($u, $skip, $itemshow - 1) ;
+    } elsif ( $u->has_sticky_entry && $skip) {
+        $delayed_entries = LJ::DelayedEntry->get_entries_by_journal($u, $skip - 1, $itemshow + 1);
     } else {
-        $delayed_entries = LJ::DelayedEntry->get_entries_by_journal($u, $skip, $itemshow + 1) || [];
+        $delayed_entries = LJ::DelayedEntry->get_entries_by_journal($u, $skip, $itemshow + 1);
     }
 
+    if (!$delayed_entries) {
+        $delayed_entries = [];
+    }
+
+    if ( $skip && $usual_skip < 0 && $u->has_sticky_entry ) {
+        $usual_skip = 1;
+    } elsif ( $skip && $usual_skip < 0) {
+        $usual_skip = 0;
+    }
+
     my $itemshow_usual = $itemshow - scalar(@$delayed_entries);
     if ( $itemshow <= scalar(@$delayed_entries) ) {
-            $itemshow_usual = -1;
+            $itemshow_usual -= 1;
     }
-    
+
     ## load the itemids
     my @itemids;
     my $err;
@@ -95,7 +109,7 @@
         'userid' => $u->{'userid'},
         'remote' => $remote,
         'itemshow' => $itemshow_usual + 1,
-        'skip' => $skip,
+        'skip' => $usual_skip,
         'tagids' => $opts->{tagids},
         'tagmode' => $opts->{tagmode},
         'security' => $opts->{'securityfilter'},
@@ -105,14 +119,15 @@
             ? "logtime" : "",
         'err' => \$err,
         'poster'  => $get->{'poster'} || '',
-        'show_sticky_on_top' => 1,
+        'show_sticky_on_top' => !$skip,
     }) if ($itemshow_usual >= 0) ;
     
     my $is_prev_exist = scalar @items + scalar(@$delayed_entries) - $itemshow > 0 ? 1 : 0;
     if ($is_prev_exist) {
-        pop @items;
         if ( scalar(@$delayed_entries) > $itemshow ) {
             pop @$delayed_entries;
+        } elsif ( scalar(@items) + scalar(@$delayed_entries) > $itemshow ) {
+            pop @items;
         }
     }
 
@@ -145,10 +160,10 @@
     my $tags = LJ::Tags::get_logtagsmulti($idsbyc);
 
     my $userlite_journal = UserLite($u);
-    my $sticky_appended = 0;
+    my $sticky_appended = !$u->has_sticky_entry() || $skip;
     
-    if (scalar(@$delayed_entries) > 0 && $itemshow_usual < 0) {
-        __append_delayed( $u, $delayed_entries,  $p->{'entries'});
+    if ( scalar(@$delayed_entries) > 0 && ( $sticky_appended && $u->has_sticky_entry()) ) {
+        __append_delayed( $u, $delayed_entries,  $p->{'entries'} );
     }
     
   ENTRY:
@@ -161,7 +176,7 @@
         my $entry_obj = LJ::Entry->new($u, ditemid => $ditemid);
         
         # append delayed entries
-        if ( !$entry_obj->is_sticky() && !$sticky_appended) {
+        if ( $entry_obj->is_sticky() && $sticky_appended) {
             __append_delayed( $u, $delayed_entries,  $p->{'entries'});
             $sticky_appended = 1;
         }
@@ -280,14 +295,14 @@
         
         push @{$p->{'entries'}}, $entry;
         LJ::run_hook('notify_event_displayed', $entry_obj);
+
+        # append delayed entries
+        if ( !$sticky_appended) {
+            __append_delayed( $u, $delayed_entries,  $p->{'entries'});
+            $sticky_appended = 1;
+        }
         
     } # end huge while loop
-    
-    # append delayed entries
-    if ( !$sticky_appended) {
-        __append_delayed( $u, $delayed_entries,  $p->{'entries'});
-        $sticky_appended = 1;
-    }
 
     # mark last entry as closing.
     $p->{'entries'}->[-1]->{'end_day'} = 1 if @{$p->{'entries'} || []};

Tags: livejournal, madeon, pm
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