I've got your suggested patch running in our production environment now with a 
slight modification:

diff --git a/core/src/main/java/hudson/Functions.java 
b/core/src/main/java/hudson/Functions.java
index 12a2c9b..fc38a02 100644
--- a/core/src/main/java/hudson/Functions.java
+++ b/core/src/main/java/hudson/Functions.java
@@ -1009,25 +1009,16 @@ public class Functions {
 
         Item i=p;
         String url = "";
-        Collection<TopLevelItem> viewItems;
-        if (view != null) {
-            viewItems = view.getItems();
-        } else {
-            viewItems = Collections.emptyList();
-        }
         while(true) {
             ItemGroup ig = i.getParent();
             url = i.getShortUrl()+url;
-
+            String viewBaseUrl = ancestors.get(view);
+            if (viewBaseUrl == null) {
+                viewBaseUrl = request.getContextPath();
+            }
             if(ig== Jenkins.getInstance() || (view != null && ig == 
view.getOwnerItemGroup())) {
                 assert i instanceof TopLevelItem;
-                if(viewItems.contains((TopLevelItem)i)) {
-                    // if p and the current page belongs to the same view, 
then return a relative path
-                    return normalizeURI(ancestors.get(view)+'/'+url);
-                } else {
-                    // otherwise return a path from the root Hudson
-                    return 
normalizeURI(request.getContextPath()+'/'+p.getUrl());
-                }
+                return normalizeURI(viewBaseUrl +'/'+url);
             }
 
             path = ancestors.get(ig);


The problem with the original suggestion was that if the ancestors doesn't 
contain a view, like on slave and label pages the url would be skewed.
I had it manually tested with ListView, inside a Sectioned View and inside a 
Nested View. And also on Personal views and Team Views.
But we are not using the folders plugin so there could be issues with that.



Robert Sandell
Sony Mobile Communications
Tel: +46 10 80 12721
sonymobile.com

-----Original Message-----
From: [email protected] [mailto:[email protected]] On 
Behalf Of Jesse Glick
Sent: den 27 mars 2014 18:42
To: [email protected]
Subject: Re: Massive performance decrease in ListView when upgrading to LTS 
1.532

Well-known problem:

https://issues.jenkins-ci.org/browse/JENKINS-18364

Also:

https://issues.jenkins-ci.org/browse/JENKINS-20052

Alas the current behavior of ListView.getAllItems is not at all adequately 
tested, given the interacting possibilities of

· explicitly listed items
· recursive views
· item regexps
· status filtering
· ViewJobFilter’s, which can
  · remove otherwise visible items
  · add otherwise unmentioned or excluded items
  · depend on, or even countermand, other filters

so making casual changes before a full test suite has been written would be 
unwise.

Regarding the immediate problem, which is the excessive calls to 
getRelativeLinkTo, I am wondering whether as I suggested in

https://issues.jenkins-ci.org/browse/JENKINS-19310

it would not be better to abandon ${jobBaseURL} and the complex code which 
generates relative links, always emitting absolute links (that is, absolute 
within the server: ${rootURL}/${item.url}), using something similar to 
AbstractItem.getUrl to automatically include the current (Ancestor) view in the 
link where applicable (so 
/jenkins/job/someFolder/view/currentView/job/includedJob/).

Alternately, just hack getRelativeLinkTo to not call View.getItems at all, and 
produce a URL under the assumption that the item is in the ancestor view. Even 
if it were not, it would not actually matter unless a View subclass overrode 
getItem(String) to verify that the named item was a member—the default 
implementation does not do so, and ListView does not override it. In other 
words, see if the following helps and introduces no obvious problem:

diff --git a/core/src/main/java/hudson/Functions.java
b/core/src/main/java/hudson/Functions.java
index 4899606..3326e66 100644
--- a/core/src/main/java/hudson/Functions.java
+++ b/core/src/main/java/hudson/Functions.java
@@ -1014,25 +1014,14 @@ public class Functions {

         Item i=p;
         String url = "";
-        Collection<TopLevelItem> viewItems;
-        if (view != null) {
-            viewItems = view.getItems();
-        } else {
-            viewItems = Collections.emptyList();
-        }
         while(true) {
             ItemGroup ig = i.getParent();
             url = i.getShortUrl()+url;

             if(ig== Jenkins.getInstance() || (view != null && ig ==
view.getOwnerItemGroup())) {
                 assert i instanceof TopLevelItem;
-                if(viewItems.contains((TopLevelItem)i)) {
-                    // if p and the current page belongs to the same
view, then return a relative path
-                    return normalizeURI(ancestors.get(view)+'/'+url);
-                } else {
-                    // otherwise return a path from the root Hudson
-                    return
normalizeURI(request.getContextPath()+'/'+p.getUrl());
-                }
+                // assume p and the current page belong to the same
view, so return a relative path
+                return normalizeURI(ancestors.get(view)+'/'+url);
             }

             path = ancestors.get(ig);
diff --git a/core/src/test/java/hudson/FunctionsTest.java
b/core/src/test/java/hudson/FunctionsTest.java
index a35cce9..c6ee303 100644
--- a/core/src/test/java/hudson/FunctionsTest.java
+++ b/core/src/test/java/hudson/FunctionsTest.java
@@ -42,6 +42,7 @@ import java.util.logging.LogRecord;

 import jenkins.model.Jenkins;

+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.jvnet.hudson.test.Bug;
@@ -135,6 +136,7 @@ public class FunctionsTest {
         assertEquals("job/i/", result);
     }

+    @Ignore("too expensive to make it correct")
     @Test
     @PrepareForTest({Stapler.class, Jenkins.class})
     public void testGetRelativeLinkTo_JobNotContainedInView() throws Exception{

--
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to