mirror of
https://github.com/langgenius/dify.git
synced 2026-03-01 12:55:13 +00:00
fix: add partial indexes on conversations for app_id with created_at/updated_at to resolve slow chat-conversations query
This commit is contained in:
@@ -21,17 +21,17 @@ def upgrade():
|
||||
'conversation_app_created_at_idx',
|
||||
['app_id', sa.literal_column('created_at DESC')],
|
||||
unique=False,
|
||||
postgresql_where=sa.text('is_deleted = false'),
|
||||
postgresql_where=sa.text('is_deleted IS false'),
|
||||
)
|
||||
batch_op.create_index(
|
||||
'conversation_app_updated_at_idx',
|
||||
['app_id', sa.literal_column('updated_at DESC')],
|
||||
unique=False,
|
||||
postgresql_where=sa.text('is_deleted = false'),
|
||||
postgresql_where=sa.text('is_deleted IS false'),
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
with op.batch_alter_table('conversations', schema=None) as batch_op:
|
||||
batch_op.drop_index('conversation_app_updated_at_idx', postgresql_where=sa.text('is_deleted = false'))
|
||||
batch_op.drop_index('conversation_app_created_at_idx', postgresql_where=sa.text('is_deleted = false'))
|
||||
batch_op.drop_index('conversation_app_updated_at_idx', postgresql_where=sa.text('is_deleted IS false'))
|
||||
batch_op.drop_index('conversation_app_created_at_idx', postgresql_where=sa.text('is_deleted IS false'))
|
||||
|
||||
@@ -715,13 +715,13 @@ class Conversation(Base):
|
||||
"conversation_app_created_at_idx",
|
||||
"app_id",
|
||||
sa.text("created_at DESC"),
|
||||
postgresql_where=sa.text("is_deleted = false"),
|
||||
postgresql_where=sa.text("is_deleted IS false"),
|
||||
),
|
||||
sa.Index(
|
||||
"conversation_app_updated_at_idx",
|
||||
"app_id",
|
||||
sa.text("updated_at DESC"),
|
||||
postgresql_where=sa.text("is_deleted = false"),
|
||||
postgresql_where=sa.text("is_deleted IS false"),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user