You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/01/07 03:51:48 UTC
[shardingsphere] branch master updated: Reduce computing overhead in SingleTableRule (#14590)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 264b0d7 Reduce computing overhead in SingleTableRule (#14590)
264b0d7 is described below
commit 264b0d7e69b92c17a203dcac8b6f7a25cac55b8a
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Fri Jan 7 11:51:05 2022 +0800
Reduce computing overhead in SingleTableRule (#14590)
---
.../singletable/rule/SingleTableRule.java | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
index aa773c3..87aeb61 100644
--- a/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
+++ b/shardingsphere-kernel/shardingsphere-single-table/shardingsphere-single-table-core/src/main/java/org/apache/shardingsphere/singletable/rule/SingleTableRule.java
@@ -38,9 +38,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Objects;
import java.util.Optional;
-import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
@@ -97,9 +95,21 @@ public final class SingleTableRule implements SchemaRule, DataNodeContainedRule,
* @return whether single tables are in same data source or not
*/
public boolean isSingleTablesInSameDataSource(final Collection<String> singleTableNames) {
- Set<String> dataSourceNames = singleTableNames.stream().map(each -> findSingleTableDataNode(each)
- .orElse(null)).filter(Objects::nonNull).map(DataNode::getDataSourceName).collect(Collectors.toSet());
- return dataSourceNames.size() <= 1;
+ String firstFoundDataSourceName = null;
+ for (String each : singleTableNames) {
+ Optional<DataNode> dataNode = findSingleTableDataNode(each);
+ if (!dataNode.isPresent()) {
+ continue;
+ }
+ if (null == firstFoundDataSourceName) {
+ firstFoundDataSourceName = dataNode.get().getDataSourceName();
+ continue;
+ }
+ if (!firstFoundDataSourceName.equals(dataNode.get().getDataSourceName())) {
+ return false;
+ }
+ }
+ return true;
}
/**