mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2025-12-14 08:06:23 +08:00
[Enhance] Performance optimization
- Change journal mode to WAL and enlarge cache size for sqlite3 database - Use monkey patch to do asynchrony - Make gevent use Flask's logger
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from .config_manager import Config
|
||||
|
||||
ARCAEA_SERVER_VERSION = 'v2.10.0.2'
|
||||
ARCAEA_SERVER_VERSION = 'v2.10.0.3'
|
||||
|
||||
|
||||
class Constant:
|
||||
|
||||
@@ -258,13 +258,17 @@ class UserPlay(UserScore):
|
||||
|
||||
def get_play_state(self) -> None:
|
||||
'''检查token,当然这里不管有没有,是用来判断世界模式和课题模式的'''
|
||||
if self.token == '1145141919810':
|
||||
# 硬编码检查,绕过数据库
|
||||
self.is_world_mode = False
|
||||
self.course_play_state = -1
|
||||
return None
|
||||
|
||||
self.c.execute(
|
||||
'''select * from songplay_token where token=:a ''', {'a': self.song_token})
|
||||
x = self.c.fetchone()
|
||||
if not x:
|
||||
self.is_world_mode = False
|
||||
self.course_play_state = -1
|
||||
return None
|
||||
raise NoData('No token data.')
|
||||
self.song.set_chart(x[2], x[3])
|
||||
if x[4]:
|
||||
self.course_play = CoursePlay(self.c, self.user, self)
|
||||
|
||||
@@ -12,8 +12,8 @@ class Connect:
|
||||
|
||||
def __init__(self, file_path=Constant.SQLITE_DATABASE_PATH):
|
||||
"""
|
||||
数据库连接,默认连接arcaea_database.db\
|
||||
接受:文件路径\
|
||||
数据库连接,默认连接arcaea_database.db\
|
||||
接受:文件路径\
|
||||
返回:sqlite3连接操作对象
|
||||
"""
|
||||
self.file_path = file_path
|
||||
|
||||
@@ -314,4 +314,7 @@ primary key(course_id, item_id, type)
|
||||
);
|
||||
|
||||
create index if not exists best_score_1 on best_score (song_id, difficulty);
|
||||
create index if not exists download_token_1 on download_token (song_id, file_name);
|
||||
create index if not exists download_token_1 on download_token (song_id, file_name);
|
||||
|
||||
PRAGMA journal_mode = WAL;
|
||||
PRAGMA default_cache_size = 8000;
|
||||
@@ -1,13 +1,7 @@
|
||||
# encoding: utf-8
|
||||
|
||||
import os
|
||||
import sys
|
||||
from importlib import import_module
|
||||
from logging.config import dictConfig
|
||||
from multiprocessing import Process, set_start_method
|
||||
from traceback import format_exc
|
||||
|
||||
from flask import Flask, make_response, request, send_from_directory
|
||||
|
||||
from core.config_manager import Config, ConfigManager
|
||||
|
||||
@@ -15,6 +9,18 @@ if os.path.exists('config.py') or os.path.exists('config'):
|
||||
# 导入用户自定义配置
|
||||
ConfigManager.load(import_module('config').Config)
|
||||
|
||||
if Config.USE_GEVENT_WSGI:
|
||||
# 异步
|
||||
from gevent import monkey
|
||||
monkey.patch_all()
|
||||
|
||||
|
||||
import sys
|
||||
from logging.config import dictConfig
|
||||
from multiprocessing import Process, set_start_method
|
||||
from traceback import format_exc
|
||||
|
||||
from flask import Flask, make_response, request, send_from_directory
|
||||
|
||||
import api
|
||||
import server
|
||||
@@ -98,7 +104,7 @@ def tcp_server_run():
|
||||
host_port = (Config.HOST, Config.PORT)
|
||||
app.logger.info('Running gevent WSGI server... (%s:%s)' % host_port)
|
||||
from gevent.pywsgi import WSGIServer
|
||||
WSGIServer(host_port, app).serve_forever()
|
||||
WSGIServer(host_port, app, log=app.logger).serve_forever()
|
||||
else:
|
||||
if Config.SSL_CERT and Config.SSL_KEY:
|
||||
app.run(Config.HOST, Config.PORT, ssl_context=(
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
flask>=2.0.2
|
||||
cryptography>=35.0.0
|
||||
cryptography>=3.0.0
|
||||
limits>=2.7.0
|
||||
|
||||
Reference in New Issue
Block a user