Add indexes and pagination to improve app performance
This commit is contained in:
@@ -7,7 +7,7 @@ class User(UserMixin, db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
username = db.Column(db.String(255), nullable=False, unique=True)
|
||||
password_hash = db.Column(db.Text, nullable=False)
|
||||
profile = db.relationship('Profile', backref='user', uselist=False)
|
||||
profile = db.relationship('Profile', backref='user', uselist=False, lazy='joined')
|
||||
|
||||
class Profile(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
@@ -19,8 +19,13 @@ class Profile(db.Model):
|
||||
diastolic_threshold = db.Column(db.Integer, default=90)
|
||||
dark_mode = db.Column(db.Boolean, default=False)
|
||||
timezone = db.Column(db.String(50), default='UTC') # e.g., 'Australia/Sydney'
|
||||
updated_at = db.Column(db.DateTime, default=db.func.now(), onupdate=db.func.now())
|
||||
|
||||
class Reading(db.Model):
|
||||
__table_args__ = (
|
||||
db.Index('ix_reading_user_timestamp', 'user_id', 'timestamp'),
|
||||
)
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
||||
timestamp = db.Column(db.DateTime, nullable=False)
|
||||
|
||||
Reference in New Issue
Block a user