You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Express中API调用提示结果行数超限的解决方法咨询

问题描述

我开发了一个Express应用,通过API调用获取结果并返回,代码如下:

const PORT = 8000
const express = require ('express')
const cors = require('cors')
const axios = require('axios')

app.use(cors())

const app = express()

app.get('/acs_chart', (req,res) => { 
  (API Call)
  async function APICall(){
    const result = await fetch(url, opts).then(res => res.json()) 
      
    res.json(result)
  }
  bitqueryAPICall()
  
}
)

app.listen(8000, () => console.log(`Server is running on port ${PORT}`))

调用API后返回错误提示:

Limit for result exceeded, max rows: 25.00 thousand, current rows: 40.11 thousand

我知道可以调整文件大小,但这不影响最大行数限制,请问是否有方法提升最大行数限制?

解决方案
  • 升级API服务套餐
    这类带行数限制的API,通常会通过付费升级套餐来提升返回行数配额。你可以查看对应API(从函数名看大概率是Bitquery)的官方套餐说明,确认高等级套餐是否包含更大的行数上限。

  • 分页拆分请求
    若暂时不想升级,可通过分页拆分请求来获取全部数据:

    1. 查阅API文档,确认是否支持分页参数(比如page、limit、offset,或者时间范围筛选参数)
    2. 将单次请求拆分为多次,每次请求获取不超过25000行的数据,最后在Express服务中合并结果返回给前端。

    示例修改思路:

    app.get('/acs_chart', async (req,res) => { 
      async function fetchAllData() {
        const allResults = [];
        let currentPage = 1;
        const pageSize = 25000;
        let hasMore = true;
    
        while(hasMore) {
          // 根据API规则拼接分页参数
          const paginatedUrl = `${url}?page=${currentPage}&limit=${pageSize}`;
          const result = await fetch(paginatedUrl, opts).then(res => res.json());
          
          allResults.push(...result.data);
          // 判断是否还有剩余数据
          hasMore = result.data.length === pageSize;
          currentPage++;
        }
    
        res.json(allResults);
      }
    
      try {
        await fetchAllData();
      } catch(err) {
        res.status(500).json({error: err.message});
      }
    })
    
  • 优化查询条件
    缩小数据范围,比如添加时间过滤、特定字段筛选等条件,让单次API返回的行数控制在25000以内。例如查询链上数据时,限定只返回最近7天或特定地址的相关数据。

内容的提问来源于stack exchange,提问作者Ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 06:27:29