public int getTiedJobCount ( ) { if ( tiedJobsCount != - 1 ) return tiedJobsCount ; // denormalize for performance // we don't need to respect security as much when returning a simple count SecurityContext context = ACL . impersonate ( ACL . SYSTEM ) ; try { int result = 0 ; // top level gives the map without checking security of items in the map // therefore best performance for ( TopLevelItem topLevelItem : Jenkins . getInstance ( ) . getItemMap ( ) . values ( ) ) { if ( topLevelItem instanceof AbstractProject ) { final AbstractProject project = ( AbstractProject ) topLevelItem ; if ( matches ( project . getAssignedLabelString ( ) ) ) { result ++ ; } } if ( topLevelItem instanceof ItemGroup ) { Stack < ItemGroup > q = new Stack <> ( ) ; q . push ( ( ItemGroup ) topLevelItem ) ; while ( ! q . isEmpty ( ) ) { ItemGroup < ? > parent = q . pop ( ) ; // we run the risk of permissions checks in ItemGroup#getItems() // not much we can do here though for ( Item i : parent . getItems ( ) ) { if ( i instanceof AbstractProject ) { final AbstractProject project = ( AbstractProject ) i ; if ( matches ( project . getAssignedLabelString ( ) ) ) { result ++ ; } } if ( i instanceof ItemGroup ) { q . push ( ( ItemGroup ) i ) ; } } } } } return tiedJobsCount = result ; } finally { SecurityContextHolder . setContext ( context ) ; } }
Returns an approximate count of projects that are tied on this node .