Add discovery search history with auto-save, fix timeout causing search failure

- Save every search result to DB for later review
- Add '搜索历史' tab with timeline view, load/delete records
- Raise discovery search timeout from 30s to 120s (Bing Puppeteer needs ~40s)
- Reduce search queries from 4 to 3 for faster response
- New model: DiscoveryRecord (user_id, product, market, companies JSON)
- API: POST/GET/DELETE /api/v1/discovery/records
- Migration: discovery_records table
This commit is contained in:
TradeMate Dev
2026-05-27 15:54:50 +08:00
parent 6f0d8b0fb4
commit c1638db6b2
8 changed files with 308 additions and 10 deletions
@@ -0,0 +1,39 @@
"""add discovery_records table
Revision ID: 0798c5c09c8c
Revises: 7fe16f1f9962
Create Date: 2026-05-27 15:54:21.092439
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision: str = '0798c5c09c8c'
down_revision: Union[str, None] = '7fe16f1f9962'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('discovery_records',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('user_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('product', sa.String(length=500), nullable=False),
sa.Column('market', sa.String(length=200), nullable=True),
sa.Column('companies', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_discovery_records_user_id'), 'discovery_records', ['user_id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_discovery_records_user_id'), table_name='discovery_records')
op.drop_table('discovery_records')
# ### end Alembic commands ###