refactor: adjust database indexes by adding high-frequency composite indexes and removing redundant id indexes

This commit is contained in:
jxxghp
2026-05-09 20:04:05 +08:00
parent ac11b303b3
commit cd5e693302
12 changed files with 346 additions and 25 deletions
+6 -2
View File
@@ -1,6 +1,6 @@
from typing import Optional
from sqlalchemy import Column, Integer, String, JSON, select
from sqlalchemy import Column, Integer, String, JSON, Index, select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import Session
@@ -29,12 +29,16 @@ class Message(Base):
# 用户ID
userid = Column(String)
# 登记时间
reg_time = Column(String, index=True)
reg_time = Column(String)
# 消息方向:0-接收息,1-发送消息
action = Column(Integer)
# 附件json
note = Column(JSON)
__table_args__ = (
Index('ix_message_reg_time_id', 'reg_time', 'id'),
)
@classmethod
@db_query
def list_by_page(cls, db: Session, page: Optional[int] = 1, count: Optional[int] = 30):