From e996d0cd536cd81d3c4ffb8191c111fec5dd794b Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 20 Sep 2023 14:46:09 -0400 Subject: [PATCH] Optimization for `AbstractLazyLoadRunMap.loadNumberOnDisk` (#8494) --- .../java/jenkins/model/lazy/AbstractLazyLoadRunMap.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java b/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java index edd335372e6b..4d2710282ade 100644 --- a/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java +++ b/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java @@ -51,6 +51,7 @@ import java.util.function.IntConsumer; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Pattern; import jenkins.util.MemoryReductionUtil; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; @@ -332,6 +333,8 @@ public synchronized void purgeCache() { loadNumberOnDisk(); } + private static final Pattern BUILD_NUMBER = Pattern.compile("[0-9]+"); + private void loadNumberOnDisk() { String[] kids = dir.list(); if (kids == null) { @@ -340,10 +343,14 @@ private void loadNumberOnDisk() { } SortedIntList list = new SortedIntList(kids.length / 2); for (String s : kids) { + if (!BUILD_NUMBER.matcher(s).matches()) { + // not a build directory + continue; + } try { list.add(Integer.parseInt(s)); } catch (NumberFormatException e) { - // this isn't a build dir + // matched BUILD_NUMBER but not an int? } } list.sort();