feat(floor): add surroundings API for lazy loading by ranking#220
Open
feat(floor): add surroundings API for lazy loading by ranking#220
Conversation
GET /floors/{id}/surroundings?size=10
Loads floors around a target floor's ranking position, returning up to
2*size+1 floors. Uses the existing (hole_id, ranking) composite index
for efficient range queries, avoiding full hole loading for floor
navigation.
Closes #67
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
新增
GET /floors/{id}/surroundings?size=10接口,支持按楼层位置懒加载周围楼层。Closes #67问题:前端跳转到任意楼层时需要加载整个洞的所有 floor,高回复数的洞性能差。
方案:根据目标 floor 的
ranking,加载其前后各size个楼层(默认 10),返回最多2 * size + 1个 floor。利用已有的(hole_id, ranking)复合唯一索引,两次查询完成:hole_id和rankingranking BETWEEN范围查询加载周围楼层改动
apis/floor/schemas.go— 新增SurroundingModel(size 参数,默认 10,最大 50)apis/floor/apis.go— 新增GetFloorSurroundingshandlerapis/floor/routes.go— 注册GET /floors/:id/surroundingstests/floor_test.go— 新增TestGetFloorSurroundings(中间位置、自定义 size、边界、404)使用示例