Skip to content

feat(floor): add surroundings API for lazy loading by ranking#220

Open
Acture wants to merge 1 commit intomainfrom
feat/floor-surroundings
Open

feat(floor): add surroundings API for lazy loading by ranking#220
Acture wants to merge 1 commit intomainfrom
feat/floor-surroundings

Conversation

@Acture
Copy link
Copy Markdown
Contributor

@Acture Acture commented Mar 27, 2026

Summary

新增 GET /floors/{id}/surroundings?size=10 接口,支持按楼层位置懒加载周围楼层。Closes #67

问题:前端跳转到任意楼层时需要加载整个洞的所有 floor,高回复数的洞性能差。

方案:根据目标 floor 的 ranking,加载其前后各 size 个楼层(默认 10),返回最多 2 * size + 1 个 floor。利用已有的 (hole_id, ranking) 复合唯一索引,两次查询完成:

  1. 由 floor ID 查出 hole_idranking
  2. ranking BETWEEN 范围查询加载周围楼层

改动

  • apis/floor/schemas.go — 新增 SurroundingModel(size 参数,默认 10,最大 50)
  • apis/floor/apis.go — 新增 GetFloorSurroundings handler
  • apis/floor/routes.go — 注册 GET /floors/:id/surroundings
  • tests/floor_test.go — 新增 TestGetFloorSurroundings(中间位置、自定义 size、边界、404)

使用示例

GET /api/floors/12345/surroundings        → 返回 ranking ±10 范围内的楼层
GET /api/floors/12345/surroundings?size=5  → 返回 ranking ±5 范围内的楼层

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
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.

任意楼定位的懒加载

1 participant