Skip to content

Commit

Permalink
Preload users when loading strats to speed up loading esp public strats
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanrdoherty committed Mar 20, 2024
1 parent ec42435 commit 8572888
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Strategy> builtStrategies = new ArrayList<>();
UnbuildableStrategyList<InvalidStrategyStructureException> malstructuredStrategies = new UnbuildableStrategyList<>();
UnbuildableStrategyList<WdkModelException> 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));
Expand Down
5 changes: 5 additions & 0 deletions Model/src/main/java/org/gusdb/wdk/model/user/UserCache.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,6 +26,10 @@ public UserCache(User user) {
_userFactory = null;
}

public void loadUsersByIds(List<Long> userIds) {
putAll(_userFactory.getUsersById(userIds));
}

@Override
public User get(Object id) {
try {
Expand Down

0 comments on commit 8572888

Please sign in to comment.