**feat(folder-resource): add offset and limit pagination for sub-folder search#35618
Conversation
…er search** - Updated `FolderHelper` to support pagination via `offset` and `limit` parameters in `findSubFoldersPathByParentPath` method. - Modified hardcoded limit to 40 and introduced an effective limit to handle `-1` (unlimited) cases. - Refactored `findSubfoldersUnderHost` and `findSubfoldersUnderFolder` to include pagination logic. - Adjusted return logic to paginate results using `subList` for accurate slicing. - Enhanced `FolderResource` API to accept `offset` and `limit` as query parameters for sub-folder search requests. - Updated OpenAPI documentation to reflect the new pagination parameters. - Added comprehensive integration tests in `FolderResourceTest` to validate pagination behavior, including offset handling, custom limits, and default limit scenarios. - Verified backward compatibility for unlimited results (`limit=-1`) and ensured proper response for offset-beyond-result cases. ref: #31934 Signed-off-by: erickgonzalez <erick.gonzalez@dotcms.com>
|
Claude finished @erickgonzalez's task in 3m 16s —— View job PR ReviewSolid, well-tested change overall. The validation, overflow guard, and integration test coverage are good. A few things worth a second look before merge: 1. The
|
…overflow guard, safety cap Address review feedback on the byPath pagination work: - Validate offset/limit at the REST layer: reject offset<0, limit==0, and limit<-1 with 400 (previously caused 500 IndexOutOfBoundsException / IllegalArgumentException). - Overflow-safe effectiveLimit via long intermediate clamped to Integer.MAX_VALUE; prior offset+limit could overflow to a negative int. - Cap "unlimited" (limit=-1) at SUB_FOLDER_UNLIMITED_SAFETY_CAP (10000) instead of Integer.MAX_VALUE to bound worst-case in-memory work. - Return a fresh ArrayList copy of the subList slice to avoid backing-list aliasing. - OpenAPI @parameter descriptions document offset>=0 and the -1 sentinel with its safety cap. - Fix pre-existing typo "must be send" -> "must be sent". Tests added: negative offset, negative limit != -1, limit==0, and overflow input (offset=Integer.MAX_VALUE-5, limit=100). All 22 FolderResourceTest integration tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Adds
offsetandlimitquery parameters toPOST /api/v1/folder/byPathto fix silent truncation of folder lists. Closes #34505.FolderHelperto support pagination viaoffsetandlimitparameters infindSubFoldersPathByParentPathmethod.limit=-1is treated as "unlimited" but bounded bySUB_FOLDER_UNLIMITED_SAFETY_CAP(10000) to avoid OOM on very large sites.findSubfoldersUnderHostandfindSubfoldersUnderFolderto accepteffectiveLimit.subList(offset, offset+limit)wrapped in a freshArrayListto avoid backing-list aliasing.FolderResource.findSubFoldersByPathnow validates inputs (offset >= 0,limit > 0orlimit == -1) and returns 400 on bad input.effectiveLimitcomputation via alongintermediate clamped toInteger.MAX_VALUE.-1sentinel and the safety cap.limit=-1, negative offset/limit,limit=0, overflow input, and fewer-than-default-folders.The endpoint previously returned at most 20 subfolders silently (hardcoded). It now returns at most 40 by default. Existing clients that omit
offset/limitwill receive more results than before. This is intentional and addresses the bug described in #34505. Worth a regression sanity check on:/api/v1/folder/byPathDotFolderService.getFolders()callersScope
This PR covers the BE side only. Follow-up tickets will wire the new pagination params into Content Drive and the Host/Folder Field in the new edit contentlet.
Test plan
./mvnw verify -pl :dotcms-integration -Dcoreit.test.skip=false -Dit.test=FolderResourceTest— all 22 tests passref: #34505
This PR fixes: #31934