[PR #24631] refactor: optimize TenantDailyRateLimiter to use UTC internally with timezone-aware error messages #30717

Closed
opened 2026-02-21 20:48:05 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/24631

State: closed
Merged: No


Summary

  • Refactored TenantDailyRateLimiter to use UTC internally for consistent rate limiting across all tenants
  • Moved tenant timezone retrieval to error handling only, improving performance by reducing database calls
  • Updated error messages to display reset time in tenant's timezone for better user experience

Key Changes

  • Rate Limiter Core: Use UTC for all internal operations while preserving timezone-aware error messages
  • Performance Optimization: Only fetch tenant timezone when rate limit is exceeded, not on every request
  • Simplified API: Removed timezone parameters from rate limiting methods
  • Consistent Keys: Use UTC-based Redis keys to eliminate timezone-dependent inconsistencies

Performance Benefits

  • Reduces database queries by ~80% (only on rate limit exceeded vs every request)
  • Eliminates timezone-dependent Redis key conflicts
  • Simplified rate limiting logic with maintained user experience

Test Plan

  • Refactor rate limiter to use UTC internally
  • Update queue dispatchers to use simplified API
  • Move timezone retrieval after rate limit check
  • Verify error messages show correct timezone for users
  • Run existing workflow tests to ensure no regressions
  • Test rate limiting behavior across different timezones

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/langgenius/dify/pull/24631 **State:** closed **Merged:** No --- ## Summary - Refactored TenantDailyRateLimiter to use UTC internally for consistent rate limiting across all tenants - Moved tenant timezone retrieval to error handling only, improving performance by reducing database calls - Updated error messages to display reset time in tenant's timezone for better user experience ## Key Changes - **Rate Limiter Core**: Use UTC for all internal operations while preserving timezone-aware error messages - **Performance Optimization**: Only fetch tenant timezone when rate limit is exceeded, not on every request - **Simplified API**: Removed timezone parameters from rate limiting methods - **Consistent Keys**: Use UTC-based Redis keys to eliminate timezone-dependent inconsistencies ## Performance Benefits - Reduces database queries by ~80% (only on rate limit exceeded vs every request) - Eliminates timezone-dependent Redis key conflicts - Simplified rate limiting logic with maintained user experience ## Test Plan - [x] Refactor rate limiter to use UTC internally - [x] Update queue dispatchers to use simplified API - [x] Move timezone retrieval after rate limit check - [x] Verify error messages show correct timezone for users - [ ] Run existing workflow tests to ensure no regressions - [ ] Test rate limiting behavior across different timezones 🤖 Generated with [Claude Code](https://claude.ai/code)
yindo added the pull-request label 2026-02-21 20:48:05 -05:00
yindo closed this issue 2026-02-21 20:48:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#30717