From 1d04b0bde07f8ff5c7685a9a7247f843e4c3824d Mon Sep 17 00:00:00 2001 From: liqiang-fit2cloud Date: Thu, 26 Dec 2024 18:21:10 +0800 Subject: [PATCH 1/2] build: remove pyc compilation. --- installer/Dockerfile | 3 +- installer/compile.py | 82 -------------------------------------------- 2 files changed, 1 insertion(+), 84 deletions(-) delete mode 100644 installer/compile.py diff --git a/installer/Dockerfile b/installer/Dockerfile index fc86061d60a..33b5349cec3 100644 --- a/installer/Dockerfile +++ b/installer/Dockerfile @@ -26,8 +26,7 @@ RUN python3 -m venv /opt/py3 && \ poetry config virtualenvs.create false && \ . /opt/py3/bin/activate && \ if [ "$(uname -m)" = "x86_64" ]; then sed -i 's/^torch.*/torch = {version = "^2.2.1+cpu", source = "pytorch"}/g' pyproject.toml; fi && \ - poetry install && \ - python3 /opt/maxkb/app/installer/compile.py + poetry install FROM ghcr.io/1panel-dev/maxkb-python-pg:python3.11-pg15.8 ARG DOCKER_IMAGE_TAG=dev \ diff --git a/installer/compile.py b/installer/compile.py deleted file mode 100644 index 4359c2e8c32..00000000000 --- a/installer/compile.py +++ /dev/null @@ -1,82 +0,0 @@ -# coding=utf-8 -""" - @project: MaxKB - @Author:虎 - @file: compile.py - @date:2024/12/23 14:11 - @desc: -""" -import os -import sys -import shutil -from py_compile import compile - - -def clean(path_str: str): - for parent, dir_name, filename in os.walk(path_str): - for dir_str in dir_name: - if dir == '__pycache__': - fullname = os.path.join(parent, dir_str) - try: - shutil.rmtree(fullname) - except Exception as e: - print("Can't clean Folder:%s, reason:%s" % (fullname, e)) - - -def compile_pyc(path_str: str): - for parent, dir_name, filename in os.walk(path_str): - for cfile in filename: - fullname = os.path.join(parent, cfile) - if cfile[-3:] == '.py': - try: - if compile(fullname): - if cfile != 'settings.py' and cfile != 'wsgi.py': - os.remove(fullname) # 删除原文件,保留settings.py和wsgi.py - else: - print("Can't compile file:%s,The original file has been retained" % fullname) - except Exception as e: - print("Can't compile file:%s, reason:%s" % (fullname, e)) - - -def move(path_str: str): - for parent, dir_name, filename in os.walk(path_str): - for c_file in filename: - fullname = os.path.join(parent, c_file) - if c_file[-4:] == '.pyc': - try: - if parent.endswith('__pycache__'): - parent_path = os.path.dirname(parent) - shutil.move(fullname, parent_path) - except Exception as e: - print("Can't move file:%s, reason:%s" % (fullname, e)) - - -def replace_name(path_str: str): - for parent, dir_name, filename in os.walk(path_str): - for c_file in filename: - fullname = os.path.join(parent, c_file) - if c_file[-4:] == '.pyc': - try: - cfile_name = '' - cfile_list = c_file.split('.') - version = sys.version_info - replace_name_str = 'cpython-' + str(version[0]) + str(version[1]) - for i in range(len(cfile_list)): - if cfile_list[i] == replace_name_str: - continue - cfile_name += cfile_list[i] - if i == len(cfile_list) - 1: - continue - cfile_name += '.' - shutil.move(fullname, os.path.join(parent, cfile_name)) - except Exception as e: - print("Can't remove file:%s, reason:%s" % (fullname, e)) - - -if __name__ == '__main__': - path = "/opt/maxkb/app/apps" - clean(path) - compile_pyc(path) - move(path) - replace_name(path) - clean(path) From 982be9543523535af5817d73adef881988531802 Mon Sep 17 00:00:00 2001 From: liqiang-fit2cloud Date: Thu, 26 Dec 2024 18:34:07 +0800 Subject: [PATCH 2/2] perf: increase MAX_OVERFLOW of database connection pool. --- apps/smartdoc/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/smartdoc/conf.py b/apps/smartdoc/conf.py index e041c85ad85..054c5d8320f 100644 --- a/apps/smartdoc/conf.py +++ b/apps/smartdoc/conf.py @@ -111,7 +111,7 @@ def get_db_setting(self) -> dict: "ENGINE": self.get('DB_ENGINE'), "POOL_OPTIONS": { "POOL_SIZE": 20, - "MAX_OVERFLOW": 5 + "MAX_OVERFLOW": 80 } }