Files
zjpb.net/PROGRESS_2026-02-23.md
2026-02-23 23:34:42 +08:00

144 lines
3.8 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ZJPB 开发进度 - 2026-02-23
## 📦 版本信息
- **最新提交**: b22627a
- **提交时间**: 2026-02-23
- **部署状态**: ✅ 代码已推送到 Gitea待手动部署
---
## 🎯 本次完成内容
### 1⃣ 性能优化(后台加载慢 >1000ms
#### NewsAdmin N+1 查询修复
-`NewsAdmin` 添加 `get_query()` 方法,使用 `joinedload` 预加载关联的 `site`
- 移除导致报错的 `get_count_query()`count 查询不支持 joinedload
#### 数据库索引优化
- 新建 `migrations/add_performance_indexes.py`
-`sites``news``tags` 表添加 10 个高频查询字段索引
- 已在生产环境执行完成
#### 管理后台统计查询优化
- 控制台首页多次统计查询合并
- `recent_sites` 改为只查必要字段,减少数据传输
---
### 2⃣ 验证码 Bug 修复
**问题**:前台点击获取新闻,输入正确验证码仍提示失败
**原因**`detail_new.html` 中 fetch 请求缺少 `credentials: 'same-origin'`,导致浏览器不发送 session cookie验证码 session 无法匹配
**修复**`templates/detail_new.html` fetch 请求中添加 `credentials: 'same-origin'`
---
### 3⃣ 后台网站管理排序修复
**问题**:网站列表按创建时间正序排列,最新的反而排在最后
**修复**`SiteAdmin` 添加 `column_default_sort = ('created_at', True)`,改为倒序
---
### 4⃣ Systemd 服务配置
**目的**:替代手动 nohup 启动,服务器重启后自动恢复
**文件**`/etc/systemd/system/zjpb.service`
```ini
[Unit]
Description=ZJPB Flask Application
After=network.target mysql.service
[Service]
Type=simple
User=root
WorkingDirectory=/opt/1panel/apps/zjpb
ExecStart=/opt/1panel/apps/zjpb/venv/bin/gunicorn -c gunicorn_config.py app:create_app()
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
```
**常用命令**
```bash
systemctl start zjpb # 启动
systemctl stop zjpb # 停止
systemctl restart zjpb # 重启
systemctl status zjpb # 状态
journalctl -u zjpb -f # 实时日志
```
**同步修改**`gunicorn_config.py``daemon = False``pidfile` 改为绝对路径
---
### 5⃣ 一键部署脚本
**文件**`update.sh`
**用法**SSH 登录服务器后执行 `./update.sh`
**功能**
1. `git pull` 拉取最新代码
2. `systemctl restart zjpb` 重启服务
3. 自动验证服务状态,失败时输出日志
---
### 6⃣ 发布策略调整
**调整前**Claude 可以直接 SSH 连接生产服务器操作,风险高
**调整后**
```
本地开发 → git push 到 Gitea → 手动 SSH → ./update.sh
```
**权限文件**`.claude/settings.local.json`
- 移除:`ssh``scp``curl``wget``cmd``powershell`
- 保留:`git` 操作、`python`/`pip`
---
## 📂 修改文件清单
| 文件 | 类型 | 说明 |
|------|------|------|
| `app.py` | 修改 | NewsAdmin joinedload、控制台查询优化、SiteAdmin 排序 |
| `templates/detail_new.html` | 修改 | fetch 添加 credentials |
| `gunicorn_config.py` | 修改 | daemon=Falsepidfile 绝对路径 |
| `.claude/settings.local.json` | 修改 | 移除 SSH 权限 |
| `update.sh` | 新增 | 一键部署脚本 |
| `migrations/add_performance_indexes.py` | 新增 | 数据库索引迁移脚本 |
| `/etc/systemd/system/zjpb.service` | 新增(仅服务器) | systemd 服务配置 |
---
## 🚀 待完成(下次登录后)
- [ ] 服务器执行 `git pull && chmod +x update.sh` 完成本次部署
---
## 🖥️ 服务器信息
- **IP**: 112.124.42.38
- **SSH**: `ssh zjpb-prod`(使用 `~/.ssh/id_rsa_atplist` 密钥)
- **项目路径**: `/opt/1panel/apps/zjpb`
- **服务管理**: `systemctl restart zjpb`
- **Gitea**: `http://server.zjpb.net:3000/jowelin/zjpb.git`
---
**开发人员**: Claude Sonnet 4.6
**项目负责人**: lisacc
**开发日期**: 2026-02-23