Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIXED JENKINS-37174] Do not enumerate section items repeatedly while…
… loading the view
- Loading branch information
1 parent
a0e46f0
commit e7ddff1
Showing
5 changed files
with
219 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!-- | ||
The MIT License | ||
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
--> | ||
|
||
<!-- | ||
Overriding https://github.com/jenkinsci/jenkins/blob/master/core/src/main/resources/hudson/model/View/index.jelly. | ||
The changes are kept minimal for easier updates. https://issues.jenkins-ci.org/browse/JENKINS-37174 | ||
--> | ||
<?jelly escape-by-default='true'?> | ||
<st:compress xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt"> | ||
<l:layout title="${it.class.name=='hudson.model.AllView' ? '%Dashboard' : it.viewName}${not empty it.ownerItemGroup.fullDisplayName?' ['+it.ownerItemGroup.fullDisplayName+']':''}" norefresh="${!it.automaticRefreshEnabled}"> | ||
<j:set var="view" value="${it}"/> <!-- expose view to the scripts we include from owner --> | ||
<st:include page="sidepanel.jelly" /> | ||
<l:main-panel> | ||
<st:include page="view-index-top.jelly" it="${it.owner}" optional="true"> | ||
<!-- allow the owner to take over the top section, but we also need the default to be backward compatible --> | ||
<div id="view-message"> | ||
<div id="systemmessage"> | ||
<j:out value="${app.systemMessage!=null ? app.markupFormatter.translate(app.systemMessage) : ''}" /> | ||
</div> | ||
<t:editableDescription permission="${it.CONFIGURE}"/> | ||
</div> | ||
</st:include> | ||
|
||
<j:if test="${view.class.name!='hudson.plugins.sectioned_view.SectionedView'}"> | ||
<!-- Do not call this as it causes all sections to filter items for no reason. --> | ||
<j:set var="items" value="${it.items}"/> | ||
</j:if> | ||
<st:include page="main.jelly" /> | ||
</l:main-panel> | ||
<l:header> | ||
<!-- for screen resolution detection --> | ||
<l:yui module="cookie" /> | ||
<script> | ||
YAHOO.util.Cookie.set("screenResolution", screen.width+"x"+screen.height); | ||
</script> | ||
</l:header> | ||
</l:layout> | ||
</st:compress> |
60 changes: 60 additions & 0 deletions
60
src/test/java/hudson/plugins/sectioned_view/SectionedViewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package hudson.plugins.sectioned_view; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import hudson.model.Descriptor; | ||
import hudson.model.ItemGroup; | ||
import hudson.util.DescribableList; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.Issue; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
public class SectionedViewTest { | ||
|
||
public @Rule JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test @Issue("JENKINS-37174") | ||
public void doNotEnumerateItemsRepeatedly() throws Exception { | ||
j.createFreeStyleProject("show"); | ||
j.createFreeStyleProject("hide"); | ||
|
||
SectionedView sw = new SectionedView("sw"); | ||
j.jenkins.addView(sw); | ||
DescribableList<SectionedViewSection, Descriptor<SectionedViewSection>> sections = (DescribableList<SectionedViewSection, Descriptor<SectionedViewSection>>) sw.getSections(); | ||
|
||
JobGraphsSection jgs = spy(new JobGraphsSection("jgs", SectionedViewSection.Width.THIRD, SectionedViewSection.Positioning.LEFT)); | ||
ListViewSection lvs = spy(new ListViewSection("lvs", SectionedViewSection.Width.THIRD, SectionedViewSection.Positioning.CENTER)); | ||
TestResultViewSection trvs = spy(new TestResultViewSection("trvs", SectionedViewSection.Width.THIRD, SectionedViewSection.Positioning.RIGHT)); | ||
sections.add(jgs); | ||
sections.add(lvs); | ||
sections.add(trvs); | ||
for (SectionedViewSection section : sections) { | ||
section.setIncludeRegex(".*show.*"); | ||
} | ||
|
||
JenkinsRule.WebClient wc = j.createWebClient(); | ||
String content = wc.getPage(j.jenkins).getWebResponse().getContentAsString(); | ||
assertThat(content, containsString("show")); | ||
assertThat(content, containsString("hide")); | ||
|
||
content = wc.getPage(sw).getWebResponse().getContentAsString(); | ||
|
||
assertThat(content, containsString("show")); | ||
assertThat(content, not(containsString("hide"))); | ||
assertThat(content, containsString("jgs")); | ||
assertThat(content, containsString("lvs")); | ||
assertThat(content, containsString("trvs")); | ||
|
||
verify(jgs, times(1)).getItems(any(ItemGroup.class)); | ||
verify(lvs, times(1)).getItems(any(ItemGroup.class)); | ||
verify(trvs, times(1)).getItems(any(ItemGroup.class)); | ||
} | ||
} | ||
|