fix: additional code quality and performance improvements
Code quality: - Remove empty except blocks with proper logging - Create shared pagination utility function - Remove duplicate UUID validation code - Fix dead code in translation.py Performance: - Fix N+1 query in followup engine (use join instead of loop) - Add eager loading for customer health scores - Create database indexes for common query patterns: - customers: (user_id, status), (user_id, last_contact_at) - payment_transactions: (user_id, created_at) - followup_logs: (user_id, customer_id) - notifications: (user_id, is_read) Configuration: - Centralize magic numbers in config.py: - Payment prices - File upload limits - Rate limiting settings - Pagination defaults - Update auth.py to use centralized rate limiting config - Update customer/product imports to use centralized upload limits - Update import_service.py to use centralized MAX_ROWS
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""add performance indexes
|
||||
|
||||
Revision ID: add_perf_indexes
|
||||
Revises: add_payment_transactions_table
|
||||
Create Date: 2026-06-11
|
||||
|
||||
Add indexes for common query patterns to improve performance.
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'add_perf_indexes'
|
||||
down_revision = 'add_payment_transactions_table'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Customer indexes
|
||||
op.create_index('ix_customer_user_status', 'customers', ['user_id', 'status'])
|
||||
op.create_index('ix_customer_user_last_contact', 'customers', ['user_id', 'last_contact_at'])
|
||||
|
||||
# Payment transaction indexes
|
||||
op.create_index('ix_payment_user_created', 'payment_transactions', ['user_id', 'created_at'])
|
||||
|
||||
# Followup log indexes
|
||||
op.create_index('ix_followup_user_customer', 'followup_logs', ['user_id', 'customer_id'])
|
||||
|
||||
# Notification indexes
|
||||
op.create_index('ix_notification_user_read', 'notifications', ['user_id', 'is_read'])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Remove indexes
|
||||
op.drop_index('ix_notification_user_read', 'notifications')
|
||||
op.drop_index('ix_followup_user_customer', 'followup_logs')
|
||||
op.drop_index('ix_payment_user_created', 'payment_transactions')
|
||||
op.drop_index('ix_customer_user_last_contact', 'customers')
|
||||
op.drop_index('ix_customer_user_status', 'customers')
|
||||
Reference in New Issue
Block a user