api-pagination by secondsky/claude-skills
npx skills add https://github.com/secondsky/claude-skills --skill api-pagination为高效处理大型数据集实现可扩展的分页策略。
| 策略 | 最佳适用场景 | 性能 |
|---|---|---|
| 偏移量/限制 | 小型数据集,简单用户界面 | O(n) |
| 游标 | 无限滚动,实时数据 | O(1) |
| 键集 | 大型数据集 | O(1) |
app.get('/products', async (req, res) => {
const page = parseInt(req.query.page) || 1;
const limit = Math.min(parseInt(req.query.limit) || 20, 100);
const offset = (page - 1) * limit;
const [products, total] = await Promise.all([
Product.find().skip(offset).limit(limit),
Product.countDocuments()
]);
res.json({
data: products,
pagination: {
page,
limit,
total,
totalPages: Math.ceil(total / limit)
}
});
});
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
app.get('/posts', async (req, res) => {
const limit = 20;
const cursor = req.query.cursor;
const query = cursor
? { _id: { $gt: Buffer.from(cursor, 'base64').toString() } }
: {};
const posts = await Post.find(query).limit(limit + 1);
const hasMore = posts.length > limit;
if (hasMore) posts.pop();
res.json({
data: posts,
nextCursor: hasMore ? Buffer.from(posts[posts.length - 1]._id).toString('base64') : null
});
});
{
"data": [...],
"pagination": {
"page": 2,
"limit": 20,
"total": 150,
"totalPages": 8
},
"links": {
"first": "/api/products?page=1",
"prev": "/api/products?page=1",
"next": "/api/products?page=3",
"last": "/api/products?page=8"
}
}
每周安装量
72
代码仓库
GitHub 星标数
91
首次出现
2026年1月22日
安全审计
已安装于
claude-code62
gemini-cli56
codex56
opencode54
cursor53
github-copilot52
Implement scalable pagination strategies for handling large datasets efficiently.
| Strategy | Best For | Performance |
|---|---|---|
| Offset/Limit | Small datasets, simple UI | O(n) |
| Cursor | Infinite scroll, real-time | O(1) |
| Keyset | Large datasets | O(1) |
app.get('/products', async (req, res) => {
const page = parseInt(req.query.page) || 1;
const limit = Math.min(parseInt(req.query.limit) || 20, 100);
const offset = (page - 1) * limit;
const [products, total] = await Promise.all([
Product.find().skip(offset).limit(limit),
Product.countDocuments()
]);
res.json({
data: products,
pagination: {
page,
limit,
total,
totalPages: Math.ceil(total / limit)
}
});
});
app.get('/posts', async (req, res) => {
const limit = 20;
const cursor = req.query.cursor;
const query = cursor
? { _id: { $gt: Buffer.from(cursor, 'base64').toString() } }
: {};
const posts = await Post.find(query).limit(limit + 1);
const hasMore = posts.length > limit;
if (hasMore) posts.pop();
res.json({
data: posts,
nextCursor: hasMore ? Buffer.from(posts[posts.length - 1]._id).toString('base64') : null
});
});
{
"data": [...],
"pagination": {
"page": 2,
"limit": 20,
"total": 150,
"totalPages": 8
},
"links": {
"first": "/api/products?page=1",
"prev": "/api/products?page=1",
"next": "/api/products?page=3",
"last": "/api/products?page=8"
}
}
Weekly Installs
72
Repository
GitHub Stars
91
First Seen
Jan 22, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code62
gemini-cli56
codex56
opencode54
cursor53
github-copilot52
飞书OpenAPI Explorer:探索和调用未封装的飞书原生API接口
37,900 周安装
C# .NET 性能优化:类型设计最佳实践与性能导向编程技巧
170 周安装
iOS云同步指南:CloudKit与iCloud Drive选择、离线优先模式与冲突解决
167 周安装
代码重构最佳实践指南:基于Fowler/Martin原则的43条规则,专为AI智能体设计
168 周安装
前端测试完整指南:Jest、React Testing Library、Cypress 单元/集成/E2E测试实践
170 周安装
流行病学分析师技能:疾病调查、风险分析与公共卫生决策指南
170 周安装
VoltAgent 最佳实践指南:Agent与Workflow选择、项目结构与代码示例
173 周安装