-
Notifications
You must be signed in to change notification settings - Fork 55
LCORE-741: refactoring quota tables statements #689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LCORE-741: refactoring quota tables statements #689
Conversation
WalkthroughThe PR refactors quota management SQL statements by extracting them from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes The refactoring follows a straightforward extraction pattern with no logic changes. Review focuses on verifying SQL constant definitions are syntactically correct and that import statements properly resolve the dependencies in Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/quota/sql.py (1)
3-45: Clean refactoring with correct SQL logic.The SQL statements are well-structured and correctly handle database-specific syntax differences between PostgreSQL and SQLite. The time-based condition
revoked_at < NOW() - INTERVALensures quotas are only updated once per period.Consider adding explicit type annotations to the constants for better IDE support and documentation:
+CREATE_QUOTA_TABLE: str = """ -CREATE_QUOTA_TABLE = """ CREATE TABLE IF NOT EXISTS quota_limits ( id text NOT NULL, subject char(1) NOT NULL, quota_limit int NOT NULL, available int, updated_at timestamp with time zone, revoked_at timestamp with time zone, PRIMARY KEY(id, subject) ); """ +INCREASE_QUOTA_STATEMENT_PG: str = """ -INCREASE_QUOTA_STATEMENT_PG = """ UPDATE quota_limits SET available=available+%s, revoked_at=NOW() WHERE subject=%s AND revoked_at < NOW() - INTERVAL %s ; """ +INCREASE_QUOTA_STATEMENT_SQLITE: str = """ -INCREASE_QUOTA_STATEMENT_SQLITE = """ UPDATE quota_limits SET available=available+?, revoked_at=datetime('now') WHERE subject=? AND revoked_at < datetime('now', ?); """ +RESET_QUOTA_STATEMENT_PG: str = """ -RESET_QUOTA_STATEMENT_PG = """ UPDATE quota_limits SET available=%s, revoked_at=NOW() WHERE subject=%s AND revoked_at < NOW() - INTERVAL %s ; """ +RESET_QUOTA_STATEMENT_SQLITE: str = """ -RESET_QUOTA_STATEMENT_SQLITE = """ UPDATE quota_limits SET available=?, revoked_at=datetime('now') WHERE subject=? AND revoked_at < datetime('now', ?); """
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/quota/__init__.py(1 hunks)src/quota/sql.py(1 hunks)src/runners/quota_scheduler.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
Use absolute imports for internal modules (e.g., from auth import get_auth_dependency)
Files:
src/quota/sql.pysrc/quota/__init__.pysrc/runners/quota_scheduler.py
**/*.py
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.py: All modules start with descriptive module-level docstrings explaining purpose
Use logger = logging.getLogger(name) for module logging after import logging
Define type aliases at module level for clarity
All functions require docstrings with brief descriptions
Provide complete type annotations for all function parameters and return types
Use typing_extensions.Self in model validators where appropriate
Use modern union syntax (str | int) and Optional[T] or T | None consistently
Function names use snake_case with descriptive, action-oriented prefixes (get_, validate_, check_)
Avoid in-place parameter modification; return new data structures instead of mutating arguments
Use appropriate logging levels: debug, info, warning, error with clear messages
All classes require descriptive docstrings explaining purpose
Class names use PascalCase with conventional suffixes (Configuration, Error/Exception, Resolver, Interface)
Abstract base classes should use abc.ABC and @AbstractMethod for interfaces
Provide complete type annotations for all class attributes
Follow Google Python docstring style for modules, classes, and functions, including Args, Returns, Raises, Attributes sections as needed
Files:
src/quota/sql.pysrc/quota/__init__.pysrc/runners/quota_scheduler.py
**/__init__.py
📄 CodeRabbit inference engine (CLAUDE.md)
Package init.py files contain brief package descriptions
Files:
src/quota/__init__.py
🧬 Code graph analysis (1)
src/runners/quota_scheduler.py (1)
src/log.py (1)
get_logger(7-13)
🔇 Additional comments (3)
src/quota/__init__.py (1)
1-1: LGTM! Docstring follows guidelines.The module docstring is concise and clearly describes the package purpose.
src/quota/sql.py (1)
1-1: LGTM! Module docstring is clear and descriptive.src/runners/quota_scheduler.py (1)
20-26: Excellent refactoring with proper absolute imports.The SQL statements have been correctly extracted to a dedicated module, and the imports follow the project's absolute import convention.
Description
LCORE-741: refactoring quota tables statements
Type of change
Related Tickets & Documents
Summary by CodeRabbit
Documentation
Refactor