mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-05 02:41:34 +00:00
perf: add index on memory.user_id
Memory queries filter by user_id (get_memories_by_user_id, delete_memories_by_user_id) but the column had no index, forcing a full table scan per request. Adds a btree index via Alembic migration plus index=True on the model so fresh installs include it.
This commit is contained in:
parent
7cfb260b8a
commit
f8b39eed19
2 changed files with 27 additions and 1 deletions
|
|
@ -0,0 +1,26 @@
|
|||
"""Add index on memory.user_id
|
||||
|
||||
Revision ID: a749ab2aa953
|
||||
Revises: c1d2e3f4a5b6
|
||||
Create Date: 2026-04-17 00:00:00.000000
|
||||
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision = 'a749ab2aa953'
|
||||
down_revision = 'c1d2e3f4a5b6'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# Memory.user_id is filtered on every per-user query
|
||||
# (get_memories_by_user_id, delete_memories_by_user_id),
|
||||
# so a btree index prevents full-table scans as the table grows.
|
||||
op.create_index('memory_user_id_idx', 'memory', ['user_id'])
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_index('memory_user_id_idx', table_name='memory')
|
||||
|
|
@ -19,7 +19,7 @@ class Memory(Base):
|
|||
__tablename__ = 'memory'
|
||||
|
||||
id = Column(String, primary_key=True, unique=True)
|
||||
user_id = Column(String)
|
||||
user_id = Column(String, index=True)
|
||||
content = Column(Text)
|
||||
updated_at = Column(BigInteger)
|
||||
created_at = Column(BigInteger)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue