diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2011-09-07 15:46:33 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2011-09-07 15:46:33 +0200 |
commit | 13d5c77e69b68e74206ea9ad5fbd4920e058e9c0 (patch) | |
tree | e0a009e4e82b592f70a2887458ee71df4db95c0a /sonar-core | |
parent | f1b9f65a7fcef6667e3376d6d26b6595446c4bf8 (diff) | |
download | sonarqube-13d5c77e69b68e74206ea9ad5fbd4920e058e9c0.tar.gz sonarqube-13d5c77e69b68e74206ea9ad5fbd4920e058e9c0.zip |
SONAR-2522 Improve the batch requests on the RULES table
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java b/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java index cf31ad3a525..f44461f5003 100644 --- a/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java +++ b/sonar-core/src/main/java/org/sonar/core/components/CacheRuleFinder.java @@ -23,6 +23,7 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.Maps; import org.sonar.api.rules.Rule; +import org.sonar.api.rules.RuleQuery; import org.sonar.jpa.session.DatabaseSessionFactory; import java.util.Map; @@ -41,34 +42,28 @@ public final class CacheRuleFinder extends DefaultRuleFinder { Rule rule = rulesById.get(ruleId); if (rule==null) { rule = doFindById(ruleId); - addToCache(rule); + loadRepository(rule.getRepositoryKey()); } return rule; } @Override - public Rule findByKey(String repositoryKey, String key) { - Map<String,Rule> repoRules = rulesByKey.get(repositoryKey); - Rule rule = null; - if (repoRules!=null) { - rule = repoRules.get(key); - } - if (rule == null) { - rule = doFindByKey(repositoryKey, key); - addToCache(rule); - } - return rule; + public Rule findByKey(String repositoryKey, String ruleKey) { + Map<String,Rule> repository = loadRepository(repositoryKey); + return repository.get(ruleKey); } - private void addToCache(Rule rule) { - if (rule != null) { - rulesById.put(rule.getId(), rule); - Map<String, Rule> repoRules = rulesByKey.get(rule.getKey()); - if (repoRules==null) { - repoRules = Maps.newHashMap(); - rulesByKey.put(rule.getRepositoryKey(), repoRules); + private Map<String,Rule> loadRepository(String repositoryKey) { + Map<String,Rule> repository = rulesByKey.get(repositoryKey); + if (repository==null) { + repository = Maps.newHashMap(); + rulesByKey.put(repositoryKey, repository); + + for (Rule rule : findAll(RuleQuery.create().withRepositoryKey(repositoryKey))) { + repository.put(rule.getKey(), rule); + rulesById.put(rule.getId(), rule); } - repoRules.put(rule.getKey(), rule); } + return repository; } } |