Skip to content

Cleanup#66

Merged
Aiiion merged 7 commits into
masterfrom
cleanup
Jun 18, 2026
Merged

Cleanup#66
Aiiion merged 7 commits into
masterfrom
cleanup

Conversation

@Aiiion

@Aiiion Aiiion commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Version information now included in contact endpoint response.
  • Bug Fixes

    • Improved search and filtering functionality in request and error logs.
    • Enhanced parameter handling for weather endpoint queries.
  • Chores

    • Version bumped to 1.6.0.
    • Optimized request log batch processing: increased batch size to 500 and reduced flush threshold to 2 minutes for faster performance.
    • Updated validation schemas for improved data consistency.

Aiiion and others added 5 commits June 18, 2026 20:51
- Increase batch size from 40 to 500 to reduce DB round-trips at volume
- Add moveAndFetchRequestLogs Lua script that atomically moves items to
  the processing list and returns them in a single Redis round-trip,
  replacing a separate move + read call per batch
- Reduce partial flush age threshold from 10 to 2 minutes so low-traffic
  logs reach Postgres within ~4 minutes instead of ~12
- Add bulkEnqueueRequestLogs using MULTI/EXEC pipeline for test setup;
  update flush tests to use it and drive counts from REQUEST_LOG_BATCH_SIZE

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Aiiion, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 18 minutes and 9 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6a9047e8-3bcb-43d0-8748-7a15287e202d

📥 Commits

Reviewing files that changed from the base of the PR and between 6d745b4 and 91e41b5.

📒 Files selected for processing (3)
  • src/controllers/v1/errorLogs.controller.mjs
  • src/controllers/v1/requestLogs.controller.mjs
  • src/utils/validationSchemas.mjs
📝 Walkthrough

Walkthrough

Version bumped to 1.6.0. Input parsing (float/int coercion, clamping, NaN filtering) moved from weather and log controllers into express-validator schemas. Two new Redis helpers added (bulkEnqueueRequestLogs, moveAndFetchRequestLogs). Flush job batch size increased to 500, age threshold reduced to 2 minutes, and the loop refactored to use the atomic move helper.

Changes

Input Validation & Controller Simplification

Layer / File(s) Summary
Validation schema contracts
src/utils/validationSchemas.mjs
New weatherValidationSchema extends latLonValidationSchema with days (default 5, capped) and units (imperial sanitized away). paginationValidationSchema.page gets a default of 1. requestLogsIndexValidationSchema.code sanitizer coerces values to integers.
Weather route + controller simplification
src/routes/v1/weather.route.mjs, src/controllers/v1/weather.controller.mjs
Route switches to weatherValidationSchema. Controller removes all manual parseFloat/parseInt/clamping for lat, lon, days, and units, passing raw destructured query values to downstream services.
Log controllers simplification
src/controllers/v1/errorLogs.controller.mjs, src/controllers/v1/requestLogs.controller.mjs
Both controllers destructure query params directly from req.query, removing inline parseInt/Math.max clamping and NaN filtering now handled by validation middleware.
Version bump + contact endpoint
package.json, src/controllers/info.controller.mjs
package.json bumped to 1.6.0; info.controller.mjs reads version via createRequire and includes it in the contact endpoint response.

Redis Queue & Flush Job Refactor

Layer / File(s) Summary
New Redis queue helpers
src/services/redis.service.mjs
bulkEnqueueRequestLogs pushes multiple payloads in a single MULTI pipeline. moveAndFetchRequestLogs uses an embedded Lua script to atomically LMOVE up to count items from the request-log queue to the processing list.
Flush job constants + batch acquisition
src/jobs/flush-request-logs.mjs
REQUEST_LOG_BATCH_SIZE raised from 40 → 500; PARTIAL_FLUSH_AGE_THRESHOLD_MS lowered from 10 min → 2 min. Flush loop normal path replaced with moveAndFetchRequestLogs; crash-recovery path clears the processing list and breaks when empty.
Flush job tests
src/tests/flush-request-logs.test.mjs
Imports updated to include bulkEnqueueRequestLogs; makeLog() factory added. All test cases rewritten to use bulkEnqueueRequestLogs and the exported batch-size/age-threshold constants.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Aiiion/express-api#5: Adds the weatherWarnings aggregation feature in the weather controller, which this PR modifies by changing how lat/lon and days are passed to that same service call.
  • Aiiion/express-api#63: Directly overlaps with this PR at src/controllers/v1/requestLogs.controller.mjs (query parsing/where/pagination logic) and src/services/redis.service.mjs (Redis request-log movement).
  • Aiiion/express-api#48: Modifies the same weatherAggregatorService.allWeather/Promise wiring in src/controllers/v1/weather.controller.mjs that this PR refactors to use raw query values.

Poem

🐇 Hop hop, the parsers have moved away,
Schemas now do the clamping each day.
The Redis queue bundles five hundred strong,
Atomic Lua scripts right where they belong.
With a version bump shining bright as the sun,
This rabbit says: clean code is truly fun! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Cleanup' is vague and generic, using a non-descriptive term that does not convey meaningful information about the actual changeset. Use a more descriptive title that captures the main changes, such as 'Refactor request log batching and validation schemas' or 'Update version, logging batch size, and weather validation'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cleanup

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
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/tests/flush-request-logs.test.mjs (1)

24-32: ⚡ Quick win

Add stable_id to the test log factory to cover dedupe-key behavior.

These tests now validate batch flushing, but the generated log payloads skip stable_id, so they don’t exercise the uniqueness/deduplication contract used by the flush path.

Suggested patch
 const makeLog = (index, overrides = {}) => ({
+  stable_id: `test-stable-id-${index}`,
   ip: '127.0.0.1',
   route: `/logs/${index}`,
   method: 'GET',
   code: 200,
   type: 'INFO',
   created_at: new Date().toISOString(),
   ...overrides,
 });

As per coding guidelines, src/jobs/flush-request-logs.mjs: "Use bulkCreate(..., { ignoreDuplicates: true }) with stable_id for request log deduplication".

🤖 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/tests/flush-request-logs.test.mjs` around lines 24 - 32, The makeLog
factory function in the test file does not include a `stable_id` property in the
returned log object, which means the test logs don't exercise the deduplication
behavior implemented in the flush-request-logs code. Add a `stable_id` field to
the object returned by the makeLog function, using the index parameter (or a
derived value from it) to generate a stable identifier that can be used for
deduplication testing. This ensures the test payloads properly cover the
uniqueness contract used by the flush path's bulkCreate call with
ignoreDuplicates.

Source: Coding guidelines

🤖 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.

Inline comments:
In `@src/utils/validationSchemas.mjs`:
- Around line 41-47: The units validation in the validationSchemas.mjs file
currently accepts any non-imperial value as true, allowing invalid inputs to
pass silently. Replace the customSanitizer with explicit validation that only
allows the values 'metric' or 'imperial' using an isIn validator, and add a
default value option to ensure the contract is strict and predictable. This
prevents invalid values like 'units=foo' from being accepted without proper
validation.

---

Nitpick comments:
In `@src/tests/flush-request-logs.test.mjs`:
- Around line 24-32: The makeLog factory function in the test file does not
include a `stable_id` property in the returned log object, which means the test
logs don't exercise the deduplication behavior implemented in the
flush-request-logs code. Add a `stable_id` field to the object returned by the
makeLog function, using the index parameter (or a derived value from it) to
generate a stable identifier that can be used for deduplication testing. This
ensures the test payloads properly cover the uniqueness contract used by the
flush path's bulkCreate call with ignoreDuplicates.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d6588d03-4e5d-423c-ae11-ebfdac7e0e1f

📥 Commits

Reviewing files that changed from the base of the PR and between 5ece575 and 6d745b4.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • package.json
  • src/controllers/info.controller.mjs
  • src/controllers/v1/errorLogs.controller.mjs
  • src/controllers/v1/requestLogs.controller.mjs
  • src/controllers/v1/weather.controller.mjs
  • src/jobs/flush-request-logs.mjs
  • src/routes/v1/weather.route.mjs
  • src/services/redis.service.mjs
  • src/tests/flush-request-logs.test.mjs
  • src/utils/validationSchemas.mjs

Comment thread src/utils/validationSchemas.mjs
Aiiion and others added 2 commits June 19, 2026 01:48
Express 5 changed req.query to a dynamic getter that re-parses the URL
on every access, so express-validator's sanitizer mutations (customSanitizer,
default, toInt) were written to a temporary object and immediately lost.

Switch requestLogs and errorLogs controllers to use matchedData(req) from
express-validator, which reads from its internal store rather than req.query.
Page defaults to 1 via destructuring since matchedData omits unprovided
optional fields.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Aiiion Aiiion merged commit c27ff85 into master Jun 18, 2026
2 checks passed
@Aiiion Aiiion deleted the cleanup branch June 18, 2026 23:53
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