konlue opened a new pull request, #7850:
URL: https://github.com/apache/shenyu/pull/7850
> **Stacked on #7844** — this branch contains the #7830 dictionary-threading
fix as its base, so the diff currently shows both changes; the #7830 portion
will drop out of this diff automatically once #7844 merges. The actual change
of this PR is the last commit (`955652a`).
Fixes #7829.
## Summary
`SensitiveWordPlugin#dictionary` parses the rule words (`split` + `contains`
dedup, O(n²)) before consulting the dictionary cache. On a cache hit the parsed
words are never used, so every hit repeats the parse for nothing.
## Modifications
- Move the `parseWords` call into the cache-miss branch, the only place the
rule words are consumed (redis merge and the redis-failure fallback).
- Widen `parseWords` to package-private so a spy can pin the parse contract
in tests.
## Verifying this change
- [x] `testCacheHitDoesNotParseTheRuleWords`: warm the cache, then assert
the second request never invokes `parseWords`. Fails on the previous code
(`NeverWantedButInvoked`).
- [x] `testCacheMissStillParsesTheRuleWords`: a miss parses exactly once and
the rule words are still enforced.
- [x] Targeted tests pass:
```bash
./mvnw -B -ntp -pl
shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-sensitive-word test
-Dtest=SensitiveWordPluginTest
```
Full `SensitiveWordPluginTest` 20/20 green.
- [x] Checkstyle passes:
```bash
./mvnw -B -ntp -pl
shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-sensitive-word checkstyle:check
```
clean.
## Notes
Miss/expiry/failure/fallback paths are unchanged; rule updates already evict
the cache entry (`SensitiveWordPluginDataHandler#removeHandle`), so a rebuild
re-parses fresh words. No measurable-gain claim beyond the removed work — the
parse cost scales with the rule word count and vanishes entirely on hits.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]