-
-
Notifications
You must be signed in to change notification settings - Fork 651
Feat: Pagespeed Graph Pagination Backend #3045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
8f57bec
0e48593
38631d2
ec93b60
9c5758d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -121,6 +121,21 @@ class MonitorModule { | |||||||||||||||
| }; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| // Helper | ||||||||||||||||
| offsetDatesByPage = (dates, dateRange, pageOffset) => { | ||||||||||||||||
| const dateOffsets = { | ||||||||||||||||
| recent: 60 * 60 * 2 * pageOffset * 1000, | ||||||||||||||||
| day: 60 * 60 * 24 * pageOffset * 1000, | ||||||||||||||||
| week: 60 * 60 * 24 * 7 * pageOffset * 1000, | ||||||||||||||||
| all: 0, | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| return { | ||||||||||||||||
| start: new Date(dates.start.getTime() - dateOffsets[dateRange]), | ||||||||||||||||
| end: new Date(new Date().getTime() - dateOffsets[dateRange]), | ||||||||||||||||
| }; | ||||||||||||||||
| }; | ||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
|
||||||||||||||||
| //Helper | ||||||||||||||||
| getMonitorChecks = async (monitorId, dateRange, sortOrder) => { | ||||||||||||||||
| const indexSpec = { | ||||||||||||||||
|
|
@@ -258,7 +273,7 @@ class MonitorModule { | |||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| getMonitorStatsById = async ({ monitorId, sortOrder, dateRange, numToDisplay, normalize }) => { | ||||||||||||||||
| getMonitorStatsById = async ({ monitorId, sortOrder, dateRange, numToDisplay, normalize, pageOffset }) => { | ||||||||||||||||
| try { | ||||||||||||||||
| // Get monitor, if we can't find it, abort with error | ||||||||||||||||
| const monitor = await this.Monitor.findById(monitorId); | ||||||||||||||||
|
|
@@ -269,9 +284,15 @@ class MonitorModule { | |||||||||||||||
| // Get query params | ||||||||||||||||
| const sort = sortOrder === "asc" ? 1 : -1; | ||||||||||||||||
|
|
||||||||||||||||
| let dates = this.getDateRange(dateRange); | ||||||||||||||||
|
|
||||||||||||||||
| if (pageOffset) { | ||||||||||||||||
| dates = this.offsetDatesByPage(dates, dateRange, pageOffset); | ||||||||||||||||
|
||||||||||||||||
| let dates = this.getDateRange(dateRange); | |
| if (pageOffset) { | |
| dates = this.offsetDatesByPage(dates, dateRange, pageOffset); | |
| if (pageOffset !== undefined && pageOffset !== null) { | |
| dates = this.offsetDatesByPage(dates, dateRange, pageOffset); | |
| } |
Evidence: symbol:getMonitorStatsById
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2 | Confidence: Medium
Speculative: The current implementation loads all checks (checksAll) into memory for every paginated request. For monitors with extensive history, this could cause performance issues. Consider implementing database-level pagination or counting instead of loading all records.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -144,6 +144,7 @@ const getMonitorStatsByIdQueryValidation = joi.object({ | |||||
| dateRange: joi.string().valid("hour", "day", "week", "month", "all"), | ||||||
| numToDisplay: joi.number(), | ||||||
| normalize: joi.boolean(), | ||||||
| pageOffset: joi.number().integer(), | ||||||
mospell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| pageOffset: joi.number().integer(), | |
| pageOffset: joi.number().integer().min(0), |
Evidence: symbol:getMonitorStatsByIdQueryValidation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1 | Confidence: High
The date offset calculation is missing support for "month" dateRange and incorrectly handles "hour" dateRange. When dateRange is "month", dateOffsets[dateRange] will be undefined, resulting in NaN date calculations that will break the query. The "hour" dateRange is supported by getDateRange() but not handled here, creating inconsistency. This will cause runtime errors for these date ranges.
Evidence: symbol:offsetDatesByPage, method:getMonitorStatsById