初始化

This commit is contained in:
2026-04-02 23:40:04 +08:00
commit 381ea7085d
107 changed files with 11858 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
# 性能规则
## 数据库优化
- 为常用查询字段添加索引(mac_address, region, school_name
- 使用连接池(pool_size=20, max_overflow=40
- 避免 N+1 查询问题
- 定期清理历史数据(保留90天)
- 使用 select_related/joinedload 预加载关联数据
**索引示例**
```python
class ONUDevice(Base):
__tablename__ = "onu_devices"
mac_address = Column(String(17), index=True)
region = Column(String(100), index=True)
school_name = Column(String(200), index=True)
```
## 缓存策略
- Redis 缓存热点数据(设备状态)
- 缓存过期时间:30分钟
- 手动刷新有5分钟冷却限制
- 使用缓存键命名规范:`device:status:{device_id}`
## 异步处理
- SSH 状态检查使用 Celery 异步任务
- 批量导入使用后台任务
- 定时任务使用 Celery Beat(每30分钟)
- 分批处理大量设备(每批100个)
## 前端优化
- 组件懒加载
- 图片懒加载
- 虚拟滚动(大列表)
- 防抖和节流
- 资源压缩和 CDN