From 418ab8a93907669be4ccbb99d7aefa5283f3e013 Mon Sep 17 00:00:00 2001 From: Daniel Vaz Gaspar Date: Tue, 17 Dec 2024 16:33:17 +0000 Subject: [PATCH] chore: improve security models performance (#2293) --- flask_appbuilder/security/sqla/models.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/flask_appbuilder/security/sqla/models.py b/flask_appbuilder/security/sqla/models.py index 680aff6a5f..74ca579bd1 100755 --- a/flask_appbuilder/security/sqla/models.py +++ b/flask_appbuilder/security/sqla/models.py @@ -6,6 +6,7 @@ Column, DateTime, ForeignKey, + Index, Integer, Sequence, String, @@ -52,6 +53,8 @@ def __repr__(self): Column("permission_view_id", Integer, ForeignKey("ab_permission_view.id")), Column("role_id", Integer, ForeignKey("ab_role.id")), UniqueConstraint("permission_view_id", "role_id"), + Index("idx_permission_view_id", "permission_view_id"), + Index("idx_role_id", "role_id"), ) @@ -72,7 +75,11 @@ def __repr__(self): class PermissionView(Model): __tablename__ = "ab_permission_view" - __table_args__ = (UniqueConstraint("permission_id", "view_menu_id"),) + __table_args__ = ( + UniqueConstraint("permission_id", "view_menu_id"), + Index("idx_permission_id", "permission_id"), + Index("idx_view_menu_id", "view_menu_id"), + ) id = Column(Integer, Sequence("ab_permission_view_id_seq"), primary_key=True) permission_id = Column(Integer, ForeignKey("ab_permission.id")) permission = relationship("Permission", lazy="joined")