Skip to content

Fix: RuleServiceImpl#searchByPage() Selectors now populated from namespace only when condition selectors are null or empty.#6305

Merged
Aias00 merged 7 commits intoapache:masterfrom
bruce121:fix/fix_admin_rule_search_by_page_logic
Mar 29, 2026
Merged

Fix: RuleServiceImpl#searchByPage() Selectors now populated from namespace only when condition selectors are null or empty.#6305
Aias00 merged 7 commits intoapache:masterfrom
bruce121:fix/fix_admin_rule_search_by_page_logic

Conversation

@bruce121
Copy link
Copy Markdown
Contributor

This commit optimizes the selector loading logic within the RuleServiceImpl#searchByPage() method.

Fixes #6304

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

@Aias00 Aias00 requested a review from Copilot March 27, 2026 05:06
@Aias00
Copy link
Copy Markdown
Contributor

Aias00 commented Mar 27, 2026

hi, pls add my wechat: aias00

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a bug in RuleServiceImpl#searchByPage() where a caller-provided selector filter could be unintentionally broadened to all selectors in the namespace, leading to incorrect rule results (e.g., KeyAuth page returning Divide rules).

Changes:

  • Update searchByPage() to populate selectors from namespace only when condition.getSelectors() is null/empty.
  • Update existing testSearchByPage expectations to reflect the corrected selector handling.
  • Add targeted test coverage for “specified selectors preserved” and “empty selectors expanded from namespace” scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java Only loads namespace selectors when the incoming selector filter is null/empty, preventing unintended query broadening.
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java Adjusts selector expectations and adds tests to validate the corrected searchByPage() behavior.
Comments suppressed due to low confidence (1)

shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java:342

  • The helper name testSelectorMergeScenario is now misleading: the updated searchByPage behavior no longer merges selector lists when a selector filter is provided. Renaming this helper (and/or its parameters like namespaceSelectorDOs) to reflect the current “populate selectors when empty” behavior would make the test intent clearer.
    private void testSelectorMergeScenario(final List<String> userSelectors,
                                           final List<SelectorDO> namespaceSelectorDOs,
                                           final int expectedSize,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +312 to +313
given(this.selectorMapper.selectAllByNamespaceId(anyString())).willReturn(Arrays.asList(selectorDO1, selectorDO2));
given(this.ruleMapper.selectByCondition(any(RuleQueryCondition.class))).willReturn(emptyPage);
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In testSearchByPageWithSpecifiedSelectors, the test stubs selectorMapper.selectAllByNamespaceId(...) even though the new behavior/optimization is that this call should not happen when selectors are already provided. Consider removing the unused stubbing and adding an explicit verify(..., never()) to ensure the namespace selector query is not triggered in this scenario (otherwise a performance regression could slip through while still passing assertions).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@Aias00 Aias00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aias00
Copy link
Copy Markdown
Contributor

Aias00 commented Mar 29, 2026

hi, pls add my wechat: aias00

@Aias00 Aias00 merged commit 0a927fd into apache:master Mar 29, 2026
41 of 53 checks passed
@bruce121 bruce121 deleted the fix/fix_admin_rule_search_by_page_logic branch March 29, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] RuleServiceImpl.searchByPage() 把“当前 selectorId”错误地扩成了“当前 namespace 下全部 selectorId”

3 participants