wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r20128: LJSUP-9890. Problem with sorting data on...

Committer: gprochaev
LJSUP-9890. Problem with sorting data on editjournal.bml

U   trunk/htdocs/editjournal.bml
Modified: trunk/htdocs/editjournal.bml
===================================================================
--- trunk/htdocs/editjournal.bml	2011-09-23 10:38:40 UTC (rev 20127)
+++ trunk/htdocs/editjournal.bml	2011-09-26 09:01:34 UTC (rev 20128)
@@ -14,6 +14,7 @@
     use LJ::Fotki::UserSpace;
     use LJ::Widget::Fotki::Upload;
     use LJ::Widget::Calendar;
+    use List::Util;
 
     my $title = BML::ml('.title');
 
@@ -644,9 +645,10 @@
         my %ymd_req = ($year && $month && $day && $show ne 'recent') ? ( ymd => $ymd ) : ();
         my @post_ids = sort { $b <=> $a } ($usejournal_u ? $usejournal_u->get_post_ids : $remote->get_post_ids);
         $only_me_checked = 1 unless $remote->can_manage ($usejournal_u);
+        my $next_page = 0;
         while ($usejournal_u && ($LJ::MAX_SCROLLBACK_LASTN = 50000,
             my @recent = LJ::get_recent_items({
-                itemshow  => $items_per_page,
+                itemshow  => $items_per_page + 1,
                 err       => \$err,
                 userid    => $usejournal_u->{userid},
                 clusterid => $usejournal_u->{clusterid},
@@ -669,17 +671,21 @@
 
             push @recent_entries, @recent;
 
-            my @temp_sort = sort { $a->{itemid} <=> $b->{itemid} } @recent_entries;
-            $start_from = $temp_sort[0]->{'itemid'};
+            $start_from = List::Util::max ( map { $_->{'itemid'} } @recent_entries );
 
-            if (@recent_entries == $items_per_page) {
-                last;
+            if (@recent_entries > $items_per_page) {
+                $next_page = $start_from - $items_per_page + 1;
+                splice @recent_entries, -1, 1;
             }
 
-            $start_from += $items_per_page;
+            last if @recent_entries >= $items_per_page;
         }
 
-        $ret .= $entry_chooser->(\@recent_entries, prev => $post_ids[0] >= $prev_page_id ? $prev_page_id : 0, 'next' => @recent_entries >= $items_per_page ? $start_from : 0);
+        my $prev_page = $start_from + $items_per_page + 1;
+        $ret .= $entry_chooser->(\@recent_entries,
+                                prev => $prev_page < $post_ids[0] || ($prev_page - $post_ids[0] < $items_per_page) ? $prev_page : 0,
+                                'next' => $next_page > 0 ? $next_page : 0
+        );
 
         my $ad = LJ::get_ads({ location => 'bml.editjournal', ljadwrapper => 1 });
         if ($ad) {

Tags: bml, livejournal, wisest-owl
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