Skip to content

Fix/db performance#366

Merged
Producdevity merged 7 commits into
stagingfrom
fix/db-performance
May 23, 2026
Merged

Fix/db performance#366
Producdevity merged 7 commits into
stagingfrom
fix/db-performance

Conversation

@Producdevity

@Producdevity Producdevity commented May 23, 2026

Copy link
Copy Markdown
Owner

Description

Reduces unnecessary database pressure in production and removes monitoring code that was giving us noisy, misleading signals.

Changes included:

  • Caps the Prisma pg adapter pool per serverless instance instead of relying on URL params that the adapter does not use.
  • Disables global React Query refetches on window focus/reconnect, with notification count opting back in where freshness matters.
  • Removes the custom DB/system monitoring page and server-side connection monitor. It was querying the same database during incidents and was not a reliable health check.
  • Removes an unused dynamic import entry.

No Vercel/Supabase env var changes are required for this PR.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactor
  • Other: production performance cleanup

How Has This Been Tested?

  • Local build
  • Lint
  • Typecheck
  • Unit tests
  • Manual testing

Screenshots (if applicable)

N/A. This removes an unused admin monitoring screen and does not add user-facing UI.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have made corresponding changes to the documentation
  • I have checked that all checks (lint, typecheck, test) pass

Notes for reviewers

Summary by CodeRabbit

  • Removed Features

    • System monitoring dashboard, its pages/widgets, and the monitoring nav item removed; related server-side monitoring endpoints and background monitors removed.
  • Bug Fixes

    • Notification center now refetches when the browser window regains focus.
  • Chores

    • Database pool sizing now derives from the connection string.
    • Client query behavior changed to disable automatic refetch on window focus and network reconnect.

Review Change Stack

@vercel

vercel Bot commented May 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
emuready Ready Ready Preview, Comment May 23, 2026 7:14pm

Request Review

@coderabbitai

coderabbitai Bot commented May 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 94ccd7e5-c4f7-4d95-abf1-2d3bdf565e95

📥 Commits

Reviewing files that changed from the base of the PR and between a07300c and 8c7ba37.

📒 Files selected for processing (1)
  • src/components/notifications/NotificationCenter.tsx

Walkthrough

This PR removes the admin monitoring dashboard and its server-side monitoring router/integration, disables global TRPC refetch-on-focus/reconnect defaults while enabling notifications refetch on window focus, derives Prisma pool sizing from DATABASE_URL, and replaces several query-batching helpers with Promise.all/direct counts.

Changes

Monitoring System Removal and Query Behavior Update

Layer / File(s) Summary
Admin monitoring navigation removal
src/app/admin/config/routes.ts, src/app/admin/data.ts
MONITORING route is removed from ADMIN_ROUTES; "System Monitoring" entry is removed from superAdminNavItems.
Server-side monitoring system removal and router migration
src/server/api/root.ts, src/server/init.ts
ConnectionMonitor import and startup initialization are removed; systemRouter wiring is removed from root TRPC router and replaced by systemsRouter under the systems key.
Prisma pool configuration from DATABASE_URL
src/server/prisma-client.ts
Added LOCAL_DATABASE_HOSTS and getPoolMax helper; createPrismaClient now conditionally applies computed max to the PrismaPg adapter.
Global TRPC query refetch settings and notification window focus
src/lib/api.tsx, src/components/notifications/NotificationCenter.tsx
Global QueryClient defaults disable refetch on window focus and reconnect; NotificationCenter explicitly enables refetchOnWindowFocus for notifications.
Remove unused dynamic import
src/lib/dynamic-imports.tsx
Removed CustomFieldList dynamic export and cleaned up related comment.
Listings page: signed-in gating and lookup cache
src/app/listings/ListingsPage.tsx
Add Clerk useUser gating, shared LOOKUP_DATA_STALE_TIME/GC_TIME, and update lookup queries to use explicit inputs and caching options.
Replace query-batching helpers
src/server/api/routers/*, src/server/services/report-stats.service.ts
Replaced batchQueries/createCountQuery/batch helpers with Promise.all and direct ctx.prisma.*.count(...) calls across listingReports, socs, mobile admin, users, and report-stats service.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix/db performance' is vague and generic, using non-descriptive formatting that doesn't clearly convey the main changes (monitoring removal, query optimization, or pool sizing). Use a more descriptive title such as 'Remove monitoring dashboard and optimize database pool sizing' to better communicate the primary changes to reviewers.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description is comprehensive, covering motivation, specific changes, testing performed, and checklist items. All required sections are present and adequately filled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/db-performance
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/db-performance

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/notifications/NotificationCenter.tsx (1)

27-35: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Consider adding refetchOnWindowFocus to the notifications list query for consistency.

Only unreadCountQuery (line 33) enables refetchOnWindowFocus, but notificationsQuery (lines 27-30) does not. This creates a brief inconsistency window: when the user returns to the tab, the badge count updates immediately but the notifications list remains stale until the next polling interval. While both queries use refetchInterval for eventual consistency, users might see a mismatch between the badge number and the visible list.

🔄 Proposed fix to align refetch behavior
 const notificationsQuery = api.notifications.get.useQuery(
   { limit: 10, offset: 0 },
-  { enabled: !!user, refetchInterval: POLLING_INTERVALS.NOTIFICATIONS },
+  { 
+    enabled: !!user, 
+    refetchOnWindowFocus: true,
+    refetchInterval: POLLING_INTERVALS.NOTIFICATIONS 
+  },
 )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/notifications/NotificationCenter.tsx` around lines 27 - 35,
The notifications list query (notificationsQuery created via
api.notifications.get.useQuery) lacks refetchOnWindowFocus while
unreadCountQuery includes it, causing badge/list inconsistencies; update
notificationsQuery's options to include refetchOnWindowFocus: true (alongside
enabled and refetchInterval) so both queries refresh when the window regains
focus and stay consistent with unreadCountQuery.
🧹 Nitpick comments (1)
src/server/prisma-client.ts (1)

6-6: ⚡ Quick win

Remove redundant [::1] entry.

When parsing a URL like postgres://[::1]:5432/db, the url.hostname property returns ::1 without brackets. The brackets are only URL delimiters for IPv6 addresses. The [::1] entry will never match and can be removed.

🧹 Proposed fix
-const LOCAL_DATABASE_HOSTS = new Set(['localhost', '127.0.0.1', '0.0.0.0', '::1', '[::1]'])
+const LOCAL_DATABASE_HOSTS = new Set(['localhost', '127.0.0.1', '0.0.0.0', '::1'])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/server/prisma-client.ts` at line 6, Remove the redundant IPv6 bracketed
entry from the LOCAL_DATABASE_HOSTS set: update the constant
LOCAL_DATABASE_HOSTS (where it's defined) to delete the string '[::1]' so the
set contains '::1' (unbracketed) only, ensuring hostname checks correctly match
IPv6 loopback addresses.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/components/notifications/NotificationCenter.tsx`:
- Around line 27-35: The notifications list query (notificationsQuery created
via api.notifications.get.useQuery) lacks refetchOnWindowFocus while
unreadCountQuery includes it, causing badge/list inconsistencies; update
notificationsQuery's options to include refetchOnWindowFocus: true (alongside
enabled and refetchInterval) so both queries refresh when the window regains
focus and stay consistent with unreadCountQuery.

---

Nitpick comments:
In `@src/server/prisma-client.ts`:
- Line 6: Remove the redundant IPv6 bracketed entry from the
LOCAL_DATABASE_HOSTS set: update the constant LOCAL_DATABASE_HOSTS (where it's
defined) to delete the string '[::1]' so the set contains '::1' (unbracketed)
only, ensuring hostname checks correctly match IPv6 loopback addresses.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ff0a4415-1736-40b2-89c7-23d2469e613e

📥 Commits

Reviewing files that changed from the base of the PR and between fbf1b04 and 09c6c1f.

📒 Files selected for processing (15)
  • src/app/admin/components/AdminNavIcon.tsx
  • src/app/admin/config/routes.ts
  • src/app/admin/data.ts
  • src/app/admin/monitoring/components/BundleSizeMonitor.tsx
  • src/app/admin/monitoring/components/DatabaseConnectionMonitor.tsx
  • src/app/admin/monitoring/components/PerformanceMetrics.tsx
  • src/app/admin/monitoring/page.tsx
  • src/components/notifications/NotificationCenter.tsx
  • src/lib/api.tsx
  • src/lib/dynamic-imports.tsx
  • src/server/api/root.ts
  • src/server/api/routers/system.ts
  • src/server/init.ts
  • src/server/prisma-client.ts
  • src/server/utils/connection-monitor.ts
💤 Files with no reviewable changes (11)
  • src/server/api/routers/system.ts
  • src/app/admin/monitoring/components/BundleSizeMonitor.tsx
  • src/app/admin/monitoring/page.tsx
  • src/app/admin/monitoring/components/PerformanceMetrics.tsx
  • src/server/utils/connection-monitor.ts
  • src/app/admin/monitoring/components/DatabaseConnectionMonitor.tsx
  • src/lib/dynamic-imports.tsx
  • src/server/init.ts
  • src/app/admin/data.ts
  • src/server/api/root.ts
  • src/app/admin/components/AdminNavIcon.tsx

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/app/listings/ListingsPage.tsx (1)

68-95: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Avoid showing role-based UI from stale users.me data after sign-out

src/app/listings/ListingsPage.tsx gates the api.users.me query with enabled: isSignedIn === true, but the render logic still uses userQuery.data directly (e.g., {userQuery.data && ...}), and there’s no app-side sign-out handler found that invalidates/clears users.me on auth transitions. Gate those UI checks with isSignedIn (or invalidate users.me on sign-out) so signed-out views can’t temporarily use cached role data.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/app/listings/ListingsPage.tsx` around lines 68 - 95, The page currently
reads userQuery.data directly which can be stale after sign-out; update render
and logic to always gate role-sensitive UI with isSignedIn (e.g., use
"isSignedIn && userQuery.data" instead of "userQuery.data") or, alternatively,
ensure users.me is cleared on sign-out by invalidating/removing the query via
the react-query/queryClient when sign-out occurs; target the
api.users.me.useQuery/userQuery and any places that reference userQuery.data
(and userPreferencesQuery) so role-based UI only renders when isSignedIn is true
or the query is explicitly cleared.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/app/listings/ListingsPage.tsx`:
- Around line 68-95: The page currently reads userQuery.data directly which can
be stale after sign-out; update render and logic to always gate role-sensitive
UI with isSignedIn (e.g., use "isSignedIn && userQuery.data" instead of
"userQuery.data") or, alternatively, ensure users.me is cleared on sign-out by
invalidating/removing the query via the react-query/queryClient when sign-out
occurs; target the api.users.me.useQuery/userQuery and any places that reference
userQuery.data (and userPreferencesQuery) so role-based UI only renders when
isSignedIn is true or the query is explicitly cleared.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 738bdfbd-a5ac-4c7b-b966-65f89fb72f4a

📥 Commits

Reviewing files that changed from the base of the PR and between 09c6c1f and a07300c.

📒 Files selected for processing (7)
  • src/app/listings/ListingsPage.tsx
  • src/server/api/routers/listingReports.ts
  • src/server/api/routers/mobile/admin.ts
  • src/server/api/routers/socs.ts
  • src/server/api/routers/users.ts
  • src/server/services/report-stats.service.ts
  • src/server/utils/query-performance.ts
💤 Files with no reviewable changes (1)
  • src/server/utils/query-performance.ts

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.

1 participant