mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 04:29:07 +08:00
feat(app_factory): speed up api startup (#11762)
Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
parent
1325246da8
commit
e86756cb39
27
api/app.py
27
api/app.py
@ -1,13 +1,30 @@
|
|||||||
from app_factory import create_app
|
from libs import version_utils
|
||||||
from libs import threadings_utils, version_utils
|
|
||||||
|
|
||||||
# preparation before creating app
|
# preparation before creating app
|
||||||
version_utils.check_supported_python_version()
|
version_utils.check_supported_python_version()
|
||||||
threadings_utils.apply_gevent_threading_patch()
|
|
||||||
|
|
||||||
|
def is_db_command():
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if len(sys.argv) > 1 and sys.argv[0].endswith("flask") and sys.argv[1] == "db":
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
# create app
|
# create app
|
||||||
app = create_app()
|
if is_db_command():
|
||||||
celery = app.extensions["celery"]
|
from app_factory import create_migrations_app
|
||||||
|
|
||||||
|
app = create_migrations_app()
|
||||||
|
else:
|
||||||
|
from app_factory import create_app
|
||||||
|
from libs import threadings_utils
|
||||||
|
|
||||||
|
threadings_utils.apply_gevent_threading_patch()
|
||||||
|
|
||||||
|
app = create_app()
|
||||||
|
celery = app.extensions["celery"]
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app.run(host="0.0.0.0", port=5001)
|
app.run(host="0.0.0.0", port=5001)
|
||||||
|
@ -98,3 +98,14 @@ def initialize_extensions(app: DifyApp):
|
|||||||
end_time = time.perf_counter()
|
end_time = time.perf_counter()
|
||||||
if dify_config.DEBUG:
|
if dify_config.DEBUG:
|
||||||
logging.info(f"Loaded {short_name} ({round((end_time - start_time) * 1000, 2)} ms)")
|
logging.info(f"Loaded {short_name} ({round((end_time - start_time) * 1000, 2)} ms)")
|
||||||
|
|
||||||
|
|
||||||
|
def create_migrations_app():
|
||||||
|
app = create_flask_app_with_configs()
|
||||||
|
from extensions import ext_database, ext_migrate
|
||||||
|
|
||||||
|
# Initialize only required extensions
|
||||||
|
ext_database.init_app(app)
|
||||||
|
ext_migrate.init_app(app)
|
||||||
|
|
||||||
|
return app
|
||||||
|
Loading…
x
Reference in New Issue
Block a user