changes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Base model with common fields
|
||||
"""
|
||||
from sqlalchemy import Column, DateTime, String
|
||||
from sqlalchemy import Column, DateTime, String, event
|
||||
from sqlalchemy.sql import func
|
||||
from app.database.base import Base
|
||||
|
||||
@@ -14,4 +14,41 @@ class TimestampMixin:
|
||||
|
||||
class BaseModel(Base, TimestampMixin):
|
||||
"""Base model class"""
|
||||
__abstract__ = True
|
||||
__abstract__ = True
|
||||
|
||||
|
||||
# Event listeners for adaptive cache integration
|
||||
@event.listens_for(BaseModel, 'after_update', propagate=True)
|
||||
def record_update(mapper, connection, target):
|
||||
"""Record data updates for adaptive cache TTL calculation"""
|
||||
try:
|
||||
from app.services.adaptive_cache import record_data_update
|
||||
table_name = target.__tablename__
|
||||
record_data_update(table_name)
|
||||
except Exception:
|
||||
# Don't fail database operations if cache tracking fails
|
||||
pass
|
||||
|
||||
|
||||
@event.listens_for(BaseModel, 'after_insert', propagate=True)
|
||||
def record_insert(mapper, connection, target):
|
||||
"""Record data inserts for adaptive cache TTL calculation"""
|
||||
try:
|
||||
from app.services.adaptive_cache import record_data_update
|
||||
table_name = target.__tablename__
|
||||
record_data_update(table_name)
|
||||
except Exception:
|
||||
# Don't fail database operations if cache tracking fails
|
||||
pass
|
||||
|
||||
|
||||
@event.listens_for(BaseModel, 'after_delete', propagate=True)
|
||||
def record_delete(mapper, connection, target):
|
||||
"""Record data deletions for adaptive cache TTL calculation"""
|
||||
try:
|
||||
from app.services.adaptive_cache import record_data_update
|
||||
table_name = target.__tablename__
|
||||
record_data_update(table_name)
|
||||
except Exception:
|
||||
# Don't fail database operations if cache tracking fails
|
||||
pass
|
||||
Reference in New Issue
Block a user