|
@@ -10,7 +10,7 @@ from open_webui.models.folders import Folders
|
|
|
from open_webui.env import SRC_LOG_LEVELS
|
|
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
-from sqlalchemy import BigInteger, Boolean, Column, String, Text, JSON
|
|
|
+from sqlalchemy import BigInteger, Boolean, Column, String, Text, JSON, Index
|
|
|
from sqlalchemy import or_, func, select, and_, text
|
|
|
from sqlalchemy.sql import exists
|
|
|
from sqlalchemy.sql.expression import bindparam
|
|
@@ -41,6 +41,20 @@ class Chat(Base):
|
|
|
meta = Column(JSON, server_default="{}")
|
|
|
folder_id = Column(Text, nullable=True)
|
|
|
|
|
|
+ __table_args__ = (
|
|
|
+ # Performance indexes for common queries
|
|
|
+ # WHERE folder_id = ...
|
|
|
+ Index("folder_id_idx", "folder_id"),
|
|
|
+ # WHERE user_id = ... AND pinned = ...
|
|
|
+ Index("user_id_pinned_idx", "user_id", "pinned"),
|
|
|
+ # WHERE user_id = ... AND archived = ...
|
|
|
+ Index("user_id_archived_idx", "user_id", "archived"),
|
|
|
+ # WHERE user_id = ... ORDER BY updated_at DESC
|
|
|
+ Index("updated_at_user_id_idx", "updated_at", "user_id"),
|
|
|
+ # WHERE folder_id = ... AND user_id = ...
|
|
|
+ Index("folder_id_user_id_idx", "folder_id", "user_id"),
|
|
|
+ )
|
|
|
+
|
|
|
|
|
|
class ChatModel(BaseModel):
|
|
|
model_config = ConfigDict(from_attributes=True)
|