Skip to content

Fix get_hot_posts ignoring the limit parameter - #519

Closed
Osamaali313 wants to merge 1 commit into
Panniantong:mainfrom
Osamaali313:fix/xueqiu-hot-posts-limit
Closed

Fix get_hot_posts ignoring the limit parameter#519
Osamaali313 wants to merge 1 commit into
Panniantong:mainfrom
Osamaali313:fix/xueqiu-hot-posts-limit

Conversation

@Osamaali313

Copy link
Copy Markdown
Contributor

Problem

XueqiuChannel.get_hot_posts(limit) (agent_reach/channels/xueqiu.py) documents its argument as limit: 最多返回条数(上限 50) ("max number of posts to return, up to 50"), but the request hard-codes the page size to count=20:

data = _get_json(
    "https://xueqiu.com/v4/statuses/public_timeline_by_category.json"
    "?since_id=-1&max_id=-1&count=20&category=-1"
)
items = data.get("list") or []
results = []
for item in items[:limit]:
    ...

The server therefore never returns more than 20 posts, and the later items[:limit] slice can only shrink those 20 — it can never reach the documented maximum. So get_hot_posts(limit=50) silently returns just 20.

Evidence (siblings prove intent)

The two sibling methods in the same file thread limit into the page-size parameter:

  • search_stock: f"?code={...}&size={limit}"
  • get_hot_stocks: f"?size={limit}&type={stock_type}"

Both then slice items[:limit]. get_hot_posts is the only one that omits limit from the request.

Reproduction

Against a stub that honors the URL's page-size (the same contract the size={limit} siblings rely on):

call before after
get_hot_posts(limit=50) 20 ❌ 50 ✅

Fix

f"?since_id=-1&max_id=-1&count={limit}&category=-1"

Matches the size={limit} pattern of both siblings so the requested count is honored.

`XueqiuChannel.get_hot_posts(limit)` documents `limit: 最多返回条数(上限 50)`,
but the request hard-codes the page size to `count=20`:

    "?since_id=-1&max_id=-1&count=20&category=-1"

so the server never returns more than 20 posts. The subsequent
`items[:limit]` slice can only shrink those 20 — it can never reach the
documented maximum of 50. `get_hot_posts(limit=50)` silently returns 20.

The two sibling methods in the same file thread `limit` into the page-size
param: `search_stock` uses `&size={limit}` and `get_hot_stocks` uses
`?size={limit}`. Do the same here so the requested count is honored.
Copilot AI review requested due to automatic review settings July 19, 2026 19:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Panniantong

Copy link
Copy Markdown
Owner

感谢贡献。该修复已在 #578 以保留你作者身份的提交 31b028f 重实现并合并到 main;同时覆盖 limit 上限 50、零值不请求、负值快速失败等边界。全量测试与 CI 已通过,因此关闭此旧 PR。

@Panniantong Panniantong closed this Aug 6, 2026
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.

3 participants