Skip to content

fix: do not recreate group if redis is empty#114

Open
toto04 wants to merge 3 commits intomainfrom
fix-redis
Open

fix: do not recreate group if redis is empty#114
toto04 wants to merge 3 commits intomainfrom
fix-redis

Conversation

@toto04
Copy link
Copy Markdown
Contributor

@toto04 toto04 commented Apr 14, 2026

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 14, 2026

Warning

Rate limit exceeded

@toto04 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes and 57 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 51 minutes and 57 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4c73809c-c9fd-486f-8a2c-bff7dbbbb4ed

📥 Commits

Reviewing files that changed from the base of the PR and between 82355b3 and 4ee3241.

📒 Files selected for processing (2)
  • src/middlewares/bot-membership-handler.ts
  • src/middlewares/message-link.ts

Walkthrough

Updated the bot-membership handler's "TEMP_groups" migration logic to optimize group lookups. When a chat ID already exists in TEMP_redis, the middleware now skips the backend group lookup and immediately proceeds. Additionally, successful backend group lookups are now cached in TEMP_redis for future requests.

Changes

Cohort / File(s) Summary
TEMP_redis Migration Logic
src/middlewares/bot-membership-handler.ts
Modified middleware to skip backend group lookup when chat ID exists in TEMP_redis cache, and to write chat IDs into TEMP_redis after successful backend lookups. Changes involve conditional flow around api.tg.groups.getById calls and TEMP_redis state management.

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: do not recreate group if redis is empty' accurately describes the main change: improving the TEMP_redis migration logic to avoid unnecessary backend group lookups and avoid recreating groups.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/middlewares/bot-membership-handler.ts`:
- Around line 55-60: The current flow returns immediately when redisCheck is
truthy and writes a permanent entry via this.TEMP_redis.write after a successful
backend query (api.tg.groups.getById.query), which can permanently skip future
reconciliation; update the TEMP cache usage so writes include an expiration
(TTL) and/or add an existence verification step: when calling
this.TEMP_redis.write(ctx.chat.id.toString(), ctx.chat.id) use the cache
client's TTL-aware API (or wrap writes to store an expiry) and ensure the
redisCheck path validates age/expiry (or performs a lightweight recheck) before
returning next(), and add explicit invalidation hooks where backend removals
occur so stale keys are removed.
- Line 57: The current call to api.tg.groups.getById.query is swallowing all
errors via .catch(() => null) which conflates transport/runtime failures with a
genuine "not found" and can incorrectly trigger GroupManagement.create; replace
the single-line .catch by explicitly distinguishing not-found (e.g., check for a
404/NotFound error from the API) from other errors: perform the call inside a
try/catch, return null only when the caught error indicates the group is absent,
and rethrow or propagate any other error so that backend failures are not
treated as "missing" (refer to the api.tg.groups.getById.query invocation and
the downstream GroupManagement.create usage to ensure the control flow is
corrected).
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a9b73114-389f-45ed-b41b-450c990b1eb1

📥 Commits

Reviewing files that changed from the base of the PR and between ced816a and 82355b3.

📒 Files selected for processing (1)
  • src/middlewares/bot-membership-handler.ts

Comment thread src/middlewares/bot-membership-handler.ts
Comment thread src/middlewares/bot-membership-handler.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