Skip to content

LPA Dashboard Speedup, issue count bug and unnecessary function calls - #1135

Merged
pooleycodes merged 4 commits into
mainfrom
1608-lpa-dashboard-speedup-pt-2
Nov 25, 2025
Merged

LPA Dashboard Speedup, issue count bug and unnecessary function calls#1135
pooleycodes merged 4 commits into
mainfrom
1608-lpa-dashboard-speedup-pt-2

Conversation

@pooleycodes

@pooleycodes pooleycodes commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

Description

Removes more unnecessary data fetch operations in dashboard.

  • FetchEntityCounts
  • FetchResources
  • FetchEntryIssueCounts

And fixes a bug to do with fetch entry issue counts being merged with the new fetch entity issue counts function created in the dashboard speedup part 1, where duplicated errors were being counted twice for the dashboard error count.

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Related Tickets & Documents

QA Instructions, Screenshots, Recordings

Dashboard should look identical to production, but be much faster.

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above.

  • Yes
  • No, and this is why: Functionally Identical, current tests already check all required data.
  • I need help with writing tests

QA sign off

  • Code has been checked and approved
  • Design has been checked and approved
  • Product and business logic has been checked and proved

Summary by CodeRabbit

  • Refactor
    • Streamlined backend processing by removing redundant upfront data fetching and consolidating sequential steps, reducing unnecessary work and improving efficiency.
    • Simplified issue aggregation so counts are grouped more predictably.
    • Cleaned up related imports and added comments/TODOs around dataset grouping and submission-deadline logic for ongoing maintenance.

✏️ Tip: You can customize this high-level summary in your review settings.

@pooleycodes pooleycodes linked an issue Nov 24, 2025 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The middleware simplifies the LPA overview data-fetching pipeline by removing unused resource and issue-count fetches (fetchResources, fetchEntryIssueCounts, fetchEntityCounts), eliminating a dependent second parallel execution block, and streamlining the issues aggregation logic to use only entity-level counts.

Changes

Cohort / File(s) Summary
Middleware simplification
src/middleware/lpa-overview.middleware.js
Removed fetchResources, fetchEntryIssueCounts, and fetchOneFromAllDatasets/fetchEntityCounts usage; eliminated the second parallel execution block; simplified groupIssuesCountsByDataset to aggregate only entityIssueCounts; refactored imports and added TODO/comments around dataset grouping and submission-deadline logic.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Req as Request
  participant MW as lpa-overview.middleware
  participant Data as Data services

  Note over Req,MW: Previous flow (simplified view)
  Req->>MW: enter middleware
  MW->>Data: parallel(fetchResources, fetchEntryIssueCounts, otherFetches)
  MW->>Data: parallel(fetchEntityCounts, dependentFetches)
  Data-->>MW: resources + entryIssueCounts + entityIssueCounts
  MW-->>Req: aggregated response

  Note over Req,MW: New flow
  Req->>MW: enter middleware
  MW->>Data: fetch only essential datasets & entity-level counts
  Data-->>MW: entityIssueCounts + otherEssentialData
  MW->>MW: groupIssuesCountsByDataset(entityIssueCounts)
  MW-->>Req: aggregated response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Inspect src/middleware/lpa-overview.middleware.js for any remaining references to removed fetches or the deleted parallel block.
  • Validate aggregation changes in groupIssuesCountsByDataset produce expected counts and shape for downstream consumers.

Possibly related PRs

Suggested reviewers

  • eveleighoj
  • DilwoarH

Poem

🐰 The rabbit nods, light on the floor,

One pipeline now, not two before.
Fewer fetches, tidy and bright,
Hops of code in morning light.
🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the three main objectives: dashboard speedup, fixing an issue count bug, and removing unnecessary function calls.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 1608-lpa-dashboard-speedup-pt-2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pooleycodes pooleycodes changed the title LPA Dashboard Speedup, issue count Bug and unnecessary function calls LPA Dashboard Speedup, issue count bug and unnecessary function calls Nov 24, 2025
@github-actions

github-actions Bot commented Nov 24, 2025

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 66.41% 6363 / 9581
🔵 Statements 66.41% 6363 / 9581
🔵 Functions 64.8% 267 / 412
🔵 Branches 80.5% 867 / 1077
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/middleware/lpa-overview.middleware.js 80.31% 78.78% 54.54% 80.31% 22, 30-31, 73-75, 87-89, 95-97, 119-130, 147-149, 159-161, 208-209, 262-270, 284, 286, 317-328, 331-343
Generated in workflow #1289 for commit cfc522b by the Vitest Coverage Report Action

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/middleware/lpa-overview.middleware.js (3)

65-75: Clarify or retire datasetSubmissionDeadlineCheck to avoid accidental use

You’ve correctly documented that this middleware is broken and unused, but it’s still exported and contains a real bug (calling next(error) without returning, then continuing to compute and calling next() again). Consider either deleting it or at least removing the export / adding a defensive return next(error) so it can’t cause subtle issues if re‑wired in later.


117-130: Unused groupResourcesByDataset is fragile if re‑enabled

groupResourcesByDataset is marked “Not used, fix or delete” but still exported and assumes req.resources is a defined array (resources.reduce(...) will throw otherwise). Either remove it entirely, or guard it with a simple if (!Array.isArray(resources)) return next(new Error(...)) before the reduce, so that any future re‑use fails safely.


316-325: Using only entityIssueCounts fixes double‑counting; consider a small robustness guard

Switching groupIssuesCountsByDataset to aggregate solely from entityIssueCounts aligns with the PR goal of eliminating duplicated issue counts and keeps req.issues in the shape expected by prepareDatasetObjects. One small hardening you might consider is:

-export function groupIssuesCountsByDataset (req, res, next) {
-  const { entityIssueCounts } = req
-
-  req.issues = entityIssueCounts.reduce((acc, current) => {
+export function groupIssuesCountsByDataset (req, res, next) {
+  const { entityIssueCounts = [] } = req
+
+  req.issues = entityIssueCounts.reduce((acc, current) => {

so a missing or undefined entityIssueCounts doesn’t cause a runtime error.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f45a522 and ffdde91.

📒 Files selected for processing (1)
  • src/middleware/lpa-overview.middleware.js (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-11-14T17:31:37.924Z
Learnt from: rosado
Repo: digital-land/submit PR: 657
File: src/services/performanceDbApi.js:290-293
Timestamp: 2024-11-14T17:31:37.924Z
Learning: In the `getEntityCounts` function in `src/services/performanceDbApi.js`, errors are already logged through the `.catch(...)` handlers on each promise in the `requests` array.

Applied to files:

  • src/middleware/lpa-overview.middleware.js
📚 Learning: 2024-11-14T16:38:49.883Z
Learnt from: rosado
Repo: digital-land/submit PR: 657
File: test/unit/middleware/issueDetails.middleware.test.js:43-43
Timestamp: 2024-11-14T16:38:49.883Z
Learning: In `test/unit/middleware/issueDetails.middleware.test.js`, template params are verified with a schema, so it's acceptable for the test expectations to use primitive values while the test input uses an object for `issueEntitiesCount`.

Applied to files:

  • src/middleware/lpa-overview.middleware.js
🧬 Code graph analysis (1)
src/middleware/lpa-overview.middleware.js (2)
src/services/performanceDbApi.js (1)
  • req (436-436)
src/middleware/common.middleware.js (15)
  • req (121-121)
  • req (122-122)
  • req (141-141)
  • req (142-142)
  • req (181-181)
  • req (222-222)
  • req (261-261)
  • req (286-286)
  • req (299-299)
  • req (378-378)
  • req (439-439)
  • req (509-509)
  • req (567-567)
  • req (574-574)
  • req (789-789)
🔇 Additional comments (2)
src/middleware/lpa-overview.middleware.js (2)

7-10: Imports now match the streamlined LPA overview pipeline

The imports list is lean and consistent with the new middleware chain (no unused fetchers like fetchResources / fetchEntryIssueCounts left behind), which helps avoid accidental reintroduction of redundant calls.


352-372: Middleware chain simplification looks correct and should improve latency

The new chain—single parallel block (org info, endpoint summary, performance‑DB entity issue counts, provisions) followed by dataset/issue grouping and template prep—removes redundant fetches and the second parallel group while keeping all data needed by prepareDatasetObjects and prepareOverviewTemplateParams. With datasetSubmissionDeadlineCheck and addNoticesToDatasets explicitly commented out, this should be functionally equivalent for the dashboard while avoiding the prior double‑counting bug.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/middleware/lpa-overview.middleware.js (2)

68-115: Consider removing dead code rather than marking with TODO.

The datasetSubmissionDeadlineCheck function references req.resources (line 69), which is no longer fetched per this PR's changes. Since the function is already commented out in the middleware chain (line 367) and marked as broken, consider removing it entirely rather than accumulating technical debt.

Would you like me to open an issue to track the removal of this dead code and the related addNoticesToDatasets function (lines 143-186)?


118-130: Remove unused function that depends on removed data.

The groupResourcesByDataset function processes req.resources (line 119), which is no longer fetched. Since this function isn't used in the middleware chain and the data it depends on has been removed, delete it rather than leaving it as dead code with a TODO marker.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffdde91 and e29318d.

📒 Files selected for processing (1)
  • src/middleware/lpa-overview.middleware.js (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-11-14T17:31:37.924Z
Learnt from: rosado
Repo: digital-land/submit PR: 657
File: src/services/performanceDbApi.js:290-293
Timestamp: 2024-11-14T17:31:37.924Z
Learning: In the `getEntityCounts` function in `src/services/performanceDbApi.js`, errors are already logged through the `.catch(...)` handlers on each promise in the `requests` array.

Applied to files:

  • src/middleware/lpa-overview.middleware.js
📚 Learning: 2024-11-14T16:38:49.883Z
Learnt from: rosado
Repo: digital-land/submit PR: 657
File: test/unit/middleware/issueDetails.middleware.test.js:43-43
Timestamp: 2024-11-14T16:38:49.883Z
Learning: In `test/unit/middleware/issueDetails.middleware.test.js`, template params are verified with a schema, so it's acceptable for the test expectations to use primitive values while the test input uses an object for `issueEntitiesCount`.

Applied to files:

  • src/middleware/lpa-overview.middleware.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: run-tests / test
🔇 Additional comments (3)
src/middleware/lpa-overview.middleware.js (3)

8-9: LGTM: Import cleanup aligns with optimization goals.

The removal of unused imports (fetchResources, fetchEntryIssueCounts, and related fetchers) is consistent with the PR's objective to eliminate unnecessary data fetch operations.


316-328: LGTM: Bug fix correctly prevents double-counting.

The simplification to use only entityIssueCounts (removing the merge with entryIssueCounts) correctly addresses the double-counting bug described in the PR. The defensive default value of [] on line 317 ensures robustness if the fetch fails.


359-359: LGTM: Removal of second parallel block completes the optimization.

Eliminating the second parallel execution block (which depended on the removed fetchers) streamlines the middleware chain and achieves the performance improvement goal stated in the PR objectives.

Comment thread src/middleware/lpa-overview.middleware.js
@pooleycodes
pooleycodes merged commit 107a747 into main Nov 25, 2025
7 of 8 checks passed
@pooleycodes
pooleycodes deleted the 1608-lpa-dashboard-speedup-pt-2 branch November 25, 2025 11:03
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.

LPA Dashboard Speedup pt 2

2 participants