apache / apache/shenyu

[BUG] — `ApiServiceImpl.listByPage`: N+1 + no SQL pagination + selects large `document` TEXT

Open
#6,673 1 comment 0 reactions 0 assignees View on GitHub
admin priority: high type: performance
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

- severity: High; files: `ApiServiceImpl.java:261-273`; SQL `mappers/api-sqlmap.xml:268-301`
- description: (1) `ApiServiceImpl` has no `@Pageable` (verified 0 occurrences); `PageResultUtils.result(pageParameter, listSupplier)` (2-arg form, `PageResultUtils.java:55-57`) applies no SQL LIMIT — full result set loaded. (2) Per-row N+1: `tagRelationMapper.selectByQuery(apiId)` then `tagMapper.selectByIds(tagIds)` per API; `tag_relation` has no index on `api_id`/`tag_id`. (3) List selects `api.document` (LONGVARCHAR/TEXT) for every row though a list view does not need it.
- impact: Unbounded memory + row count × 2 round-trips; can OOM/stall on large inventories.
- suggested_fix: Add `@Pageable`; exclude `document` from the list column list; batch-fetch tag relations for all page ids in one query.
- confidence: High

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/00-consolidated-critical-high.md`](docs/scan2-2026-08-02/00-consolidated-critical-high.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with ApiServiceImpl.java:261-273, mappers/api-sqlmap.xml:268-301, and PageResultUtils.java:55-57 to trace list construction, pagination, and tag lookups. Done means the list query applies SQL pagination, omits the document column, and tag relations and tags are fetched in batches for the page IDs without per-row lookups.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
backend, databases, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.