feat: Redis rate limiter and shared pagination helper#9
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a Redis-backed rate limiter implementation and factors repeated count(*) pagination logic into a shared helper, aligning infrastructure services with Redis and reducing query duplication across repositories.
Changes:
- Added
RedisRateLimiterServiceand wired it into the DI container as the defaultIRateLimiterService. - Introduced a shared
countAllSQL helper and updated user/role repositories to use it for pagination totals. - Replaced inline
count(*)SQL in repositories with the shared helper.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/server/infrastructure/services/redis-rate-limiter.service.ts | Adds Redis-backed rate limiter implementation. |
| src/server/infrastructure/persistence/user.pg.repository.ts | Uses shared countAll helper for total row counting. |
| src/server/infrastructure/persistence/role.pg.repository.ts | Uses shared countAll helper for totals and user-role counts. |
| src/server/infrastructure/di/container.ts | Switches rate limiter DI binding from in-memory to Redis. |
| src/server/infrastructure/db/pagination.ts | Adds reusable countAll SQL snippet for pagination. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+16
to
+21
| const redisKey = `${KEY_PREFIX}${key}`; | ||
| const count = await this.redis.incr(redisKey); | ||
|
|
||
| if (count === 1) { | ||
| await this.redis.pexpire(redisKey, windowMs); | ||
| } |
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.
No description provided.