fix: resolve issues #911 #912 #913 #914 — N+1 queries, e2e tests, coverage thresholds, structured logging - #1006
Open
khalyaro wants to merge 1 commit into
Open
Conversation
…aChain#914 Issue MettaChain#914 - Structured JSON logging - Add src/common/logger.ts (AppLogger extending ConsoleLogger) - JSON output in production, NestJS pretty-print in development - Automatic timestamp, context, correlationId on every line - Scrubs sensitive fields (password, token, apiKey, etc.) - Wire AppLogger into NestFactory.create and Bootstrap logger in main.ts Issue MettaChain#913 - Coverage thresholds for all modules in CI - Rewrite jest.config.js with global 50% threshold (statements/lines) and per-module critical thresholds: auth (60%), documents (70%), sessions/notifications/dashboard (50%), transactions (55%) - Update .github/workflows/ci.yml: replace ad-hoc documents-only coverage step with 'npm run test:cov' which enforces all thresholds Issue MettaChain#911 - Fix N+1 query patterns - sessions.service.ts getUserSessions: push active/revoked counts to DB via two parallel count() queries instead of in-memory filtering - dashboard.service.ts getQuickStats: single OR query for buyer+seller transactions; two count() queries for property totals - notifications.service.ts deliverPending: batch updateMany instead of a per-notification UPDATE loop - prisma.service.ts: add rolling-window N+1 detection in the query event handler (warns when same table queried 5+ times in 100ms) Issue MettaChain#912 - End-to-end tests for major API workflows - Add 6 new e2e test suites (46 tests, all passing): - user-registration-login.e2e.spec.ts (profile management) - property-crud-search-favorite.e2e.spec.ts (CRUD + favorites) - rbac-enforcement.e2e.spec.ts (role-based access control) - notifications.e2e.spec.ts (list/read/delete notifications) - sessions-management.e2e.spec.ts (list/rename/revoke sessions) - documents-access-control.e2e.spec.ts (document access control)
|
@khalyaro Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves four assigned issues in a single cohesive PR.
Closes #911 — Fix N+1 query patterns
sessions.service.tsgetUserSessions: replaces in-memoryfilter()on the full session array with two parallelcount()DB queries for active/revoked countsdashboard.service.tsgetQuickStats: replaces separatebuyerTransactions+sellerTransactionsqueries with a singleORquery; replaces full property array load with twocount()callsnotifications.service.tsdeliverPending: replaces the per-notificationupdateloop with a singleupdateManybatchprisma.service.ts: adds a rolling-window N+1 detector in the$on('query')handler — warns when the same table is queried 5+ times within 100 ms (development/staging only)Closes #912 — End-to-end tests for major API workflows
Six new e2e test suites (46 tests, all green):
user-registration-login.e2e.spec.tsproperty-crud-search-favorite.e2e.spec.tsrbac-enforcement.e2e.spec.tsnotifications.e2e.spec.tssessions-management.e2e.spec.tsdocuments-access-control.e2e.spec.tsCloses #913 — Coverage thresholds for all modules in CI
jest.config.js: global 50% threshold (statements/lines, 40% branches, 45% functions) with per-module overrides for critical paths:src/auth/→ 60%src/documents/→ 70% (preserving existing)src/sessions/,src/notifications/,src/dashboard/→ 50%src/transactions/→ 55%ci.yml: replaces the ad-hoc inline documents-only coverage step withnpm run test:covso all thresholds declared injest.config.jsare enforced on every CI runCloses #914 — Structured JSON logging
src/common/logger.ts: newAppLoggerclass extendingConsoleLoggerNODE_ENV=production: each line is a single JSON object withlevel,timestamp,context,correlationId,message+ extra metadatascrubSensitive()helper redacts known PII keys (password, token, apiKey, privateKey, …) from structured metadata before serialisationsrc/main.ts: usesAppLoggeras the NestJS application logger viaNestFactory.create({ logger })Testing
npm run build✅ (zero TypeScript errors)Closes #911
Closes #912
Closes #913
Closes #914