diff --git a/Model/src/main/java/org/gusdb/wdk/model/user/StrategyLoader.java b/Model/src/main/java/org/gusdb/wdk/model/user/StrategyLoader.java index 052efe513..170dfe387 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/user/StrategyLoader.java +++ b/Model/src/main/java/org/gusdb/wdk/model/user/StrategyLoader.java @@ -181,10 +181,15 @@ private SearchResult doSearch(String sql, boolean propagateBuildErrors, Object[] loadBuilders(sql, paramValues, paramTypes); // all data loaded; build steps and strats at the specified validation level - UserCache userCache = new UserCache(_userFactory); List builtStrategies = new ArrayList<>(); UnbuildableStrategyList malstructuredStrategies = new UnbuildableStrategyList<>(); UnbuildableStrategyList stratsWithBuildErrors = new UnbuildableStrategyList<>(); + + // load all the users up first (can be done in a single batch) to avoid churn + UserCache userCache = new UserCache(_userFactory); + userCache.loadUsersByIds(queryResults.getFirst().stream().map(StrategyBuilder::getUserId).collect(Collectors.toList())); + + // try to build each strategy and put in the appropriate list for (StrategyBuilder stratBuilder : queryResults.getFirst()) { try { builtStrategies.add(stratBuilder.build(userCache, _validationLevel, _fillStrategy)); diff --git a/Model/src/main/java/org/gusdb/wdk/model/user/UserCache.java b/Model/src/main/java/org/gusdb/wdk/model/user/UserCache.java index 519739b8e..19aaca2ea 100644 --- a/Model/src/main/java/org/gusdb/wdk/model/user/UserCache.java +++ b/Model/src/main/java/org/gusdb/wdk/model/user/UserCache.java @@ -1,6 +1,7 @@ package org.gusdb.wdk.model.user; import java.util.HashMap; +import java.util.List; import org.gusdb.wdk.model.WdkModelException; import org.gusdb.wdk.model.WdkRuntimeException; @@ -25,6 +26,10 @@ public UserCache(User user) { _userFactory = null; } + public void loadUsersByIds(List userIds) { + putAll(_userFactory.getUsersById(userIds)); + } + @Override public User get(Object id) { try {