perf(system): optimize large data rendering in stocktake, fix N+1 in warehouse, and add upload size limits

This commit is contained in:
DXC
2026-04-02 18:51:13 +08:00
parent a52ced0375
commit dbcb7d0d92
2 changed files with 16 additions and 3 deletions

View File

@ -27,6 +27,9 @@ UPLOAD_FOLDER = os.path.join(BASE_DIR, 'uploads')
# 允许上传的文件后缀 # 允许上传的文件后缀
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'pdf', 'doc', 'docx', 'xls', 'xlsx'} ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp', 'pdf', 'doc', 'docx', 'xls', 'xlsx'}
# ★ 文件上传安全加固:限制最大文件大小 (10MB)
MAX_CONTENT_LENGTH = 10 * 1024 * 1024 # 10MB
def allowed_file(filename): def allowed_file(filename):
return '.' in filename and \ return '.' in filename and \
@ -58,6 +61,16 @@ def upload_file():
if file.filename == '': if file.filename == '':
return jsonify({"code": 400, "msg": "未选择文件"}), 400 return jsonify({"code": 400, "msg": "未选择文件"}), 400
# ★ 文件上传安全加固:检查文件大小
file.seek(0, os.SEEK_END)
file_size = file.tell()
file.seek(0) # 重置文件指针到开头
if file_size > MAX_CONTENT_LENGTH:
return jsonify({
"code": 400,
"msg": f"文件大小超过限制 ({MAX_CONTENT_LENGTH // (1024*1024)}MB)"
}), 400
if file and allowed_file(file.filename): if file and allowed_file(file.filename):
try: try:
# 获取后缀并生成唯一文件名 # 获取后缀并生成唯一文件名

View File

@ -235,7 +235,7 @@
<div class="table-container"> <div class="table-container">
<el-table <el-table
:data="filteredListData" :data="filteredListData"
height="100%" height="600"
stripe stripe
border border
row-key="uniqueKey" row-key="uniqueKey"
@ -660,7 +660,7 @@ const resumeSession = async () => {
const res: any = await request({ const res: any = await request({
url: '/v1/inbound/stock/draft/list', url: '/v1/inbound/stock/draft/list',
method: 'get', method: 'get',
params: { page: 1, limit: 10000 } // 获取足够多的数据 params: { page: 1, limit: 500 } // ★ 限制单次加载数量,防止内存溢出
}) })
const drafts = res && res.items ? res.items : [] const drafts = res && res.items ? res.items : []
@ -983,7 +983,7 @@ const fetchInventoryList = async (silent = false) => {
method: 'get', method: 'get',
params: { params: {
page: 1, page: 1,
limit: 10000, // 获取全部已盘点记录 limit: 500, // ★ 限制单次加载数量,防止内存溢出
keyword: listKeyword.value keyword: listKeyword.value
} }
}) })