]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1169181 - The bug_user_last_visit method returns an empty array for old bugs
authorDylan Hardison <dylan@mozilla.com>
Wed, 16 Dec 2015 00:52:37 +0000 (19:52 -0500)
committerDylan Hardison <dylan@mozilla.com>
Wed, 16 Dec 2015 00:53:34 +0000 (19:53 -0500)
r=dkl,a=dkl

Bugzilla/User.pm
Bugzilla/WebService/BugUserLastVisit.pm

index 6cfef6db5d3be69cb843838b11922e4ddc7518ae..77e6cebb022b2411ac663c03be8d9a747d593479 100644 (file)
@@ -922,9 +922,10 @@ sub groups {
 }
 
 sub last_visited {
-    my ($self) = @_;
+    my ($self, $ids) = @_;
 
-    return Bugzilla::BugUserLastVisit->match({ user_id => $self->id });
+    return Bugzilla::BugUserLastVisit->match({ user_id => $self->id,
+                                               $ids ? ( bug_id => $ids ) : () });
 }
 
 sub is_involved_in_bug {
index 19a56ff46e7decdb405a29a61bf629bb53b0e893..c0281259481150ec5cd5b54c70af4f3ebba9abf6 100644 (file)
@@ -52,7 +52,7 @@ sub update {
         push(
             @results,
             $self->_bug_user_last_visit_to_hash(
-                $bug, $last_visit_ts, $params
+                $bug->id, $last_visit_ts, $params
             ));
     }
     $dbh->bz_commit_transaction();
@@ -67,27 +67,23 @@ sub get {
 
     $user->login(LOGIN_REQUIRED);
 
+    my @last_visits;
     if ($ids) {
         # Cache permissions for bugs. This highly reduces the number of calls to
         # the DB.  visible_bugs() is only able to handle bug IDs, so we have to
         # skip aliases.
         $user->visible_bugs([grep /^[0-9]$/, @$ids]);
-    }
-
-    my @last_visits = @{ $user->last_visited };
 
-    if ($ids) {
-        # remove bugs that we are not interested in if ids is passed in.
-        my %id_set = map { ($_ => 1) } @$ids;
-        @last_visits = grep { $id_set{ $_->bug_id } } @last_visits;
+        my %last_visit  = map { $_->bug_id => $_->last_visit_ts } @{ $user->last_visited($ids) };
+        @last_visits = map { $self->_bug_user_last_visit_to_hash($_->id, $last_visit{$_}, $params) } @$ids;
+    }
+    else {
+        @last_visits = map {
+            $self->_bug_user_last_visit_to_hash($_->bug_id, $_->last_visit_ts, $params)
+        } @{ $user->last_visited };
     }
 
-    return [
-        map {
-            $self->_bug_user_last_visit_to_hash($_->bug_id, $_->last_visit_ts,
-                $params)
-        } @last_visits
-    ];
+    return \@last_visits;
 }
 
 sub _bug_user_last_visit_to_hash {