perf: SQLite WAL + 复合索引 + GZip + scheduler jitter + 构建缓存
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
from sqlalchemy import Integer, String, DateTime, Text, ForeignKey
|
||||
from sqlalchemy import Index, Integer, String, DateTime, Text, ForeignKey, text
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from app.database import Base
|
||||
|
||||
@@ -19,3 +19,8 @@ class NotificationLog(Base):
|
||||
status: Mapped[str] = mapped_column(String(16), nullable=False)
|
||||
response_text: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc), index=True)
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_notif_event_created", "event_type", text("created_at DESC")),
|
||||
Index("ix_notif_status_created", "status", text("created_at DESC")),
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime, timezone
|
||||
from sqlalchemy import Integer, Text, DateTime, ForeignKey
|
||||
from sqlalchemy import Index, Integer, Text, DateTime, ForeignKey, text
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from app.database import Base
|
||||
|
||||
@@ -11,3 +11,7 @@ class UpstreamRateSnapshot(Base):
|
||||
upstream_id: Mapped[int] = mapped_column(Integer, ForeignKey("upstreams.id", ondelete="CASCADE"), index=True)
|
||||
snapshot_json: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
captured_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc), index=True)
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_snapshot_upstream_captured", "upstream_id", text("captured_at DESC")),
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
from sqlalchemy import Integer, String, Boolean, DateTime, Text, Float
|
||||
from sqlalchemy import Index, Integer, String, Boolean, DateTime, Text, Float
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from app.database import Base
|
||||
|
||||
@@ -36,3 +36,7 @@ class Upstream(Base):
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc)
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_upstream_enabled", "enabled"),
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import DateTime, ForeignKey, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy import DateTime, ForeignKey, Index, Integer, String, Text, UniqueConstraint
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.database import Base
|
||||
@@ -30,4 +30,5 @@ class UpstreamGeneratedKey(Base):
|
||||
|
||||
__table_args__ = (
|
||||
UniqueConstraint("upstream_id", "group_id", "key_name", name="uq_upstream_group_key"),
|
||||
Index("ix_key_upstream_name", "upstream_id", "key_name"),
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, Integer, String, Text, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.database import Base
|
||||
@@ -66,3 +66,8 @@ class WebsiteSyncLog(Base):
|
||||
status: Mapped[str] = mapped_column(String(16), nullable=False)
|
||||
message: Mapped[str] = mapped_column(Text, default="")
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=lambda: datetime.now(timezone.utc), index=True)
|
||||
|
||||
__table_args__ = (
|
||||
Index("ix_sync_website_created", "website_id", text("created_at DESC")),
|
||||
Index("ix_sync_binding_created", "binding_id", text("created_at DESC")),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user