Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use db pool #224

Merged
merged 1 commit into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions FasterRunner/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,31 @@

DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"ENGINE": "dj_db_conn_pool.backends.mysql",
"NAME": "fast", # 新建数据库
# 'NAME': 'fast_mb4', # 新建数据库名
"HOST": "127.0.0.1",
"USER": "root", # 数据库登录名
"PASSWORD": "root", # 数据库登录密码
"OPTIONS": {"charset": "utf8mb4"},
# 单元测试数据库
'OPTIONS': {
'charset': 'utf8mb4',
},
'POOL_OPTIONS': {
'POOL_SIZE': 20,
'MAX_OVERFLOW': 20,
'RECYCLE': 24 * 60 * 60,
'PRE_PING': True,
'ECHO': False,
'TIMEOUT': 30,
},
"TEST": {
"NAME": "test_fast_last", # 测试过程中会生成名字为test的数据库,测试结束后Django会自动删除该数据库
},
}
}



# IM_REPORT_SETTING.update({'platform_name': '银河飞梭测试平台'})

BROKER_URL = "amqp://username:password@localhost:5672//"
Expand Down
12 changes: 8 additions & 4 deletions FasterRunner/settings/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@

DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"ENGINE": "dj_db_conn_pool.backends.mysql",
"HOST": DB_HOST,
"PORT": DB_PORT,
"NAME": DB_NAME, # 新建数据库名
"USER": DB_USER, # 数据库登录名
"PASSWORD": DB_PASSWORD, # 数据库登录密码
"OPTIONS": {"charset": "utf8mb4"},
"TEST": {
# 'MIRROR': 'default', # 单元测试时,使用default的配置
# 'DEPENDENCIES': ['default']
'POOL_OPTIONS': {
'POOL_SIZE': 20,
'MAX_OVERFLOW': 20,
'RECYCLE': 24 * 60 * 60,
'PRE_PING': True,
'ECHO': False,
'TIMEOUT': 30,
},
}
}
Expand Down
12 changes: 8 additions & 4 deletions FasterRunner/settings/pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@

DATABASES = {
"default": {
"ENGINE": "django.db.backends.mysql",
"ENGINE": "dj_db_conn_pool.backends.mysql",
"HOST": MYSQL_HOST,
"NAME": DB_NAME, # 新建数据库名
"USER": DB_USER, # 数据库登录名
"PASSWORD": DB_PASSWORD, # 数据库登录密码
"OPTIONS": {"charset": "utf8mb4"},
"TEST": {
# 'MIRROR': 'default', # 单元测试时,使用default的配置
# 'DEPENDENCIES': ['default']
'POOL_OPTIONS': {
'POOL_SIZE': 20,
'MAX_OVERFLOW': 20,
'RECYCLE': 24 * 60 * 60,
'PRE_PING': True,
'ECHO': False,
'TIMEOUT': 30,
},
}
}
Expand Down
147 changes: 145 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ django-auth-ldap = "2.3.0"
pymysql = "1.1.0"
pytest = "^8.1.1"
pytest-django = "^4.8.0"
django-db-connection-pool = {extras = ["mysql"], version = "^1.2.5"}


[tool.poetry.group.dev.dependencies]
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ django-filter==2.4.0,<2.5.0
#django-auth-ldap==2.3.0
pymysql==1.1.0
pytest==8.1.1
pytest-django==4.8.0
pytest-django==4.8.0
django-db-connection-pool[mysql]==1.2.5
Loading