vadvs (vadvs) wrote in changelog,
vadvs
vadvs
changelog

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

Committer: vad
LJSUP-9890: Problem with sorting data on editjournal.bml
U   trunk/cgi-bin/LJ/User.pm
U   trunk/htdocs/editjournal.bml
Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2011-09-28 10:14:46 UTC (rev 20159)
+++ trunk/cgi-bin/LJ/User.pm	2011-09-28 10:21:56 UTC (rev 20160)
@@ -4465,6 +4465,15 @@
         }
     }
 
+    if ($opts{posterid}){
+        $query .= " AND posterid = ? ";
+        push @vals => $opts{posterid};
+    }
+    if ($opts{afterid}){
+        $query .= " AND jitemid > ? ";
+        push @vals => $opts{afterid};
+    }
+
     # filter by date, use revttime as it is indexed
     if ($opts{'start_date'} && $opts{'end_date'}) {
         # revttime is reverse event time

Modified: trunk/htdocs/editjournal.bml
===================================================================
--- trunk/htdocs/editjournal.bml	2011-09-28 10:14:46 UTC (rev 20159)
+++ trunk/htdocs/editjournal.bml	2011-09-28 10:21:56 UTC (rev 20160)
@@ -825,12 +825,26 @@
         my $err = '';
         my $usejournal_u = LJ::load_user ($usejournal || $remote->{'user'});
         my @recent_entries = ();
-        my %entry_ids = ();
-        my $prev_page_id = ($start_from > 0) ? ($start_from + $items_per_page - 1) : 0;
+
         my $ymd = join "/", ($year, $month, $day);
         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);
+
+        ## Load ids of more recent posts
+        ## (skip this step for the first page)
+        my @post_ids = ();
+        if ($start_from){
+            my %ids_opts = (afterid => $start_from);
+               $ids_opts{posterid} = $remote->userid if $only_me_checked;
+
+            @post_ids = sort { $b <=> $a } 
+                        ($usejournal_u 
+                            ? $usejournal_u->get_post_ids(%ids_opts)  
+                            : $remote->get_post_ids(%ids_opts) );
+        }
+
         my $next_page = 0;
 
         my $delayed_entries;
@@ -842,7 +856,7 @@
         my $delayed_count = scalar(@$delayed_entries) - $delayed_skip;
         my $show_usual = ($items_per_page - $delayed_count) > 0 ? $items_per_page - $delayed_count : 0;
 
-        while (($usejournal_u && ($LJ::MAX_SCROLLBACK_LASTN = 50000,
+        if (($usejournal_u && ($LJ::MAX_SCROLLBACK_LASTN = 50000,
             my @recent = LJ::get_recent_items({
                 itemshow  => $show_usual + 1,
                 err       => \$err,
@@ -855,40 +869,43 @@
                 %ymd_req,
                 ($only_me_checked) ? ('posterid' =>  $remote->{'userid'}) : (),
             }))) || $delayed_entries) {
+            
+            my $have_next_page = 0;
+            if (@recent > $show_usual){
+                $have_next_page = 1;
+                pop @recent;
+            }
 
-            ## do not process entries twice
-            @recent = grep { $entry_ids{$_->{'itemid'}} ? 0 : 1 } @recent;
-
             my @delayed = splice(@$delayed_entries, $delayed_skip, $delayed_skip + $items_per_page);
             if ($delayed_count > 0) {
                 @recent = $append_delayed->($usejournal_u, \@recent, \@delayed);
             }
             $delayed_entries = undef;
-            last unless @recent;
 
-            ## store fetched itemids
-            foreach my $item (@recent) {
-                $entry_ids{$item->{'itemid'}} = 1;
-            }
-
             push @recent_entries, @recent;
 
+            $next_page  = List::Util::min ( map { $_->{'itemid'} } @recent_entries );
             $start_from = List::Util::max ( map { $_->{'itemid'} } @recent_entries );
 
-            if (@recent_entries > $items_per_page) {
-                $next_page = $start_from - $items_per_page + 1;
-                splice @recent_entries, -1, 1;
+        }
+
+        ## calculate prev page start poin
+        ## 
+        my $prev_page_start = 0;
+        if (@post_ids){ ## not first page
+            my $pos = @post_ids - $items_per_page;
+            if ($pos < 0){
+                $prev_page_start = $post_ids[0] + 1; # from start
+            } else {
+                $prev_page_start = $post_ids[$pos];
             }
-
-            last if @recent_entries >= $items_per_page;
         }
 
-        my $prev_page = $start_from + $items_per_page + 1;
         $ret .= $entry_chooser->(\@recent_entries,
                                 delayed_next => $delayed_count > 0 ? $items_per_page + $delayed_skip : $delayed_skip,
                                 delayed_prev => $delayed_skip > 0 ? $delayed_skip - $items_per_page : 0,
-                                prev => $prev_page < $post_ids[0] || ($prev_page - $post_ids[0] < $items_per_page) ? $prev_page : 0,
-                                'next' => $next_page > 0 ? $next_page : 0
+                                prev => $prev_page_start, 
+                                next => $next_page > 0 ? $next_page : 0
         );
 
         my $ad = LJ::get_ads({ location => 'bml.editjournal', ljadwrapper => 1 });

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