diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index 5c64253..1ee18b6 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -398,4 +398,11 @@ | 序号 | 变更类型 | 说明 | 时间 | 备注 | |:---|:-----|------------|:------------------|:---------------| -| 1 | F | 删除时添加同步锁优化 | 2025-2-2 15:30:26 | 涉及到接口调整 PR-100 | \ No newline at end of file +| 1 | F | 删除时添加同步锁优化 | 2025-2-2 15:30:26 | 涉及到接口调整 PR-100 | + +# release_0.24.2 + +| 序号 | 变更类型 | 说明 | 时间 | 备注 | +|:---|:-----|---------------------|:------------------|:-------------------| +| 1 | O | findFirst 真实实现,性能优化 | 2025-2-2 15:30:26 | PR-99 | +| 2 | O | 黑白名单遍历统一优化,性能优化 | 2025-2-2 15:30:26 | PR-99 涉及到原始结果返回值调整 | \ No newline at end of file diff --git a/README.md b/README.md index bd74554..6902280 100644 --- a/README.md +++ b/README.md @@ -58,9 +58,6 @@ v0.24.0 开始内置支持对敏感词的分类细化,不过工作量比较大 [CHANGE_LOG.md](https://github.com/houbb/sensitive-word/blob/master/CHANGE_LOG.md) -### V0.23.0 - -- 结果条件拓展支持 wordTags 和 chains ### V0.24.0 @@ -70,6 +67,12 @@ v0.24.0 开始内置支持对敏感词的分类细化,不过工作量比较大 - 删除时统一添加同步锁 sync +### V0.24.2 + +- 统一黑白名单为一次遍历,性能优化 + +- 实现真实的 findFirst,性能优化 + ## 更多资料 ### 敏感词控台 @@ -108,7 +111,7 @@ v0.24.0 开始内置支持对敏感词的分类细化,不过工作量比较大 com.github.houbb sensitive-word - 0.24.1 + 0.24.2 ``` diff --git a/pom.xml b/pom.xml index 6767341..1f829ef 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.houbb sensitive-word - 0.24.1 + 0.24.2 diff --git a/release.bat b/release.bat index 8ab7049..ea94b29 100644 --- a/release.bat +++ b/release.bat @@ -10,7 +10,7 @@ ECHO "============================= RELEASE START..." :: 版本号信息(需要手动指定) :::: 旧版本名称 -SET version=0.24.1 +SET version=0.24.2 :::: 新版本名称 SET newVersion=0.25.0 :::: 组织名称 diff --git a/src/main/java/com/github/houbb/sensitive/word/api/IWordCheck.java b/src/main/java/com/github/houbb/sensitive/word/api/IWordCheck.java index ac72e8e..db9191e 100644 --- a/src/main/java/com/github/houbb/sensitive/word/api/IWordCheck.java +++ b/src/main/java/com/github/houbb/sensitive/word/api/IWordCheck.java @@ -31,6 +31,7 @@ public interface IWordCheck { * @param context 执行上下文 * @return 敏感信息对应的长度 * @since 0.0.5 + * @since 0.24.2 为了黑白名单统一,调整了对应的返回值 */ WordCheckResult sensitiveCheck(final int beginIndex, final InnerSensitiveWordContext context); diff --git a/src/main/java/com/github/houbb/sensitive/word/support/result/WordLengthResult.java b/src/main/java/com/github/houbb/sensitive/word/support/result/WordLengthResult.java index aac3136..d1888bd 100644 --- a/src/main/java/com/github/houbb/sensitive/word/support/result/WordLengthResult.java +++ b/src/main/java/com/github/houbb/sensitive/word/support/result/WordLengthResult.java @@ -1,32 +1,48 @@ package com.github.houbb.sensitive.word.support.result; +/** + * 说明:统一让黑白名单一次遍历,性能优化 + * + * @since 0.24.2 + */ public class WordLengthResult { - private int wordAllowLen; - private int wordDenyLen; + /** + * 白名单长度 + */ + private int wordAllowLen; + /** + * 黑名单长度 + */ + private int wordDenyLen; - - private WordLengthResult(){} - - public static WordLengthResult newInstance(){ + public static WordLengthResult newInstance() { return new WordLengthResult(); } - - public int wordAllowLen(){ + public int wordAllowLen() { return this.wordAllowLen; } - public WordLengthResult wordAllowLen(int wordAllowLen){ - this.wordAllowLen=wordAllowLen; + + public WordLengthResult wordAllowLen(int wordAllowLen) { + this.wordAllowLen = wordAllowLen; return this; } - public int wordDenyLen(){ + public int wordDenyLen() { return this.wordDenyLen; } - public WordLengthResult wordDenyLen(int wordDenyLen){ - this.wordDenyLen=wordDenyLen; + + public WordLengthResult wordDenyLen(int wordDenyLen) { + this.wordDenyLen = wordDenyLen; return this; } + @Override + public String toString() { + return "WordLengthResult{" + + "wordAllowLen=" + wordAllowLen + + ", wordDenyLen=" + wordDenyLen + + '}'; + } } diff --git a/src/test/java/com/github/houbb/sensitive/word/benchmark/BenchmarkBasicTest.java b/src/test/java/com/github/houbb/sensitive/word/benchmark/BenchmarkBasicTest.java index 670d08b..476bad0 100644 --- a/src/test/java/com/github/houbb/sensitive/word/benchmark/BenchmarkBasicTest.java +++ b/src/test/java/com/github/houbb/sensitive/word/benchmark/BenchmarkBasicTest.java @@ -72,44 +72,37 @@ public class BenchmarkBasicTest { } /** - * * 黑白名单一次遍历 优化前:300*他们在地铁口交易,查10000次,26183 - * * 黑白名单一次遍历 优化后:300*他们在地铁口交易,查10000次,15705 - * + * 黑白名单一次遍历 优化前:300*他们在地铁口交易,查10000次,26183 + * 黑白名单一次遍历 优化后:300*他们在地铁口交易,查10000次,15705 + * @since 0.24.2 */ @Test public void costTimeOneTraceTest() { - StringBuilder sb=new StringBuilder(); - for(int i=0;i<300;i++){ + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 300; i++) { sb.append("他们在地铁口交易").append(i); } String text = sb.toString(); // 1W 次 long start = System.currentTimeMillis(); - SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance() - .wordDeny(new IWordDeny() { - @Override - public List deny() { - return Collections.singletonList("口交"); - } - }) - .wordAllow(new IWordAllow() { - @Override - public List allow() { - return Collections.singletonList("地铁口交易"); - } - }) - .enableWordCheck(true) - .enableNumCheck(false) - .enableUrlCheck(false) - .enableEmailCheck(false) - .init(); + SensitiveWordBs sensitiveWordBs = SensitiveWordBs.newInstance().wordDeny(new IWordDeny() { + @Override + public List deny() { + return Collections.singletonList("口交"); + } + }).wordAllow(new IWordAllow() { + @Override + public List allow() { + return Collections.singletonList("地铁口交易"); + } + }).enableWordCheck(true).enableNumCheck(false).enableUrlCheck(false).enableEmailCheck(false).init(); - for(int i = 0; i < 10000; i++) { + for (int i = 0; i < 10000; i++) { sensitiveWordBs.findAll(text); } long end = System.currentTimeMillis(); - System.out.println("------------------ COST: " + (end-start)); + System.out.println("------------------ COST: " + (end - start)); } /**