History API: return up to 100 checks per resource by default (separate from page size)
This commit is contained in:
1 parent
dcc09422c9
commit
3d66b82c88
1 file changed
+7
-4
+7
-4
@@ -419,13 +419,16 @@ app.get('/api/resources/:id/history', (req, res) => {
|
||||
|
||||
// Get all resources' check history for dashboard (optimized with aggregation)
|
||||
app.get('/api/history/overview', (req, res) => {
|
||||
const { days = 7, limit = 12, page = 1, page: pageParam } = req.query;
|
||||
const pageLimit = parseInt(req.query.limit || 10); // Pagination limit (per page)
|
||||
const { days = 7, page = 1, page: pageParam } = req.query;
|
||||
// Resource pagination (number of resources per page)
|
||||
const pageLimit = parseInt(req.query.limit || 10);
|
||||
// Per-resource checks to return (independent of pageLimit)
|
||||
const checksLimit = parseInt(req.query.checks_limit || 100);
|
||||
const currentPage = Math.max(1, parseInt(pageParam || page || 1));
|
||||
const offset = (currentPage - 1) * pageLimit;
|
||||
|
||||
// Create cache key based on query parameters
|
||||
const cacheKey = `history:days=${days}:page=${currentPage}:limit=${pageLimit}`;
|
||||
const cacheKey = `history:days=${days}:page=${currentPage}:limit=${pageLimit}:checks=${checksLimit}`;
|
||||
|
||||
// Check cache first
|
||||
const cachedResult = cache.get(cacheKey);
|
||||
@@ -467,7 +470,7 @@ app.get('/api/history/overview', (req, res) => {
|
||||
WHERE resource_id = ? AND checked_at > datetime('now', ?)
|
||||
ORDER BY checked_at DESC
|
||||
LIMIT ?
|
||||
`).all(resource.id, `-${days} days`, parseInt(limit));
|
||||
`).all(resource.id, `-${days} days`, checksLimit);
|
||||
|
||||
return {
|
||||
id: resource.id,
|
||||
|
||||
Reference in new issue
Block a user