fix project root domain is empty
This commit is contained in:
parent
56c2275145
commit
8bea8baf0c
38
main.py
38
main.py
|
@ -7,9 +7,10 @@ from starlette.middleware.base import BaseHTTPMiddleware
|
|||
from starlette.staticfiles import StaticFiles
|
||||
|
||||
from core.config import *
|
||||
set_config()
|
||||
|
||||
from core.db import get_mongo_db
|
||||
|
||||
set_config()
|
||||
from starlette.requests import Request
|
||||
import asyncio
|
||||
from urllib.parse import urlparse
|
||||
|
@ -28,27 +29,28 @@ app = FastAPI()
|
|||
|
||||
from core.apscheduler_handler import scheduler
|
||||
|
||||
# async def update():
|
||||
# if float(VERSION) <= 1.2:
|
||||
# async for db in get_mongo_db():
|
||||
# cursor = db.project.find({"root_domains": ""},{"_id":1, "root_domains": 1})
|
||||
# async for document in cursor:
|
||||
# logger.info("Update found empty root_domains")
|
||||
# root_domain = []
|
||||
# for root in document["root_domains"]:
|
||||
# if root != "":
|
||||
# root_domain.append(root)
|
||||
# update_document = {
|
||||
# "$set": {
|
||||
# "root_domains": root_domain,
|
||||
# }
|
||||
# }
|
||||
# await db.project.update_one({"_id": document['_id']}, update_document)
|
||||
|
||||
async def update():
|
||||
if float(VERSION) <= 1.2:
|
||||
async for db in get_mongo_db():
|
||||
cursor = db.project.find({"root_domains": ""},{"_id":1, "root_domains": 1})
|
||||
async for document in cursor:
|
||||
logger.info("Update found empty root_domains")
|
||||
root_domain = []
|
||||
for root in document["root_domains"]:
|
||||
if root != "":
|
||||
root_domain.append(root)
|
||||
update_document = {
|
||||
"$set": {
|
||||
"root_domains": root_domain,
|
||||
}
|
||||
}
|
||||
await db.project.update_one({"_id": document['_id']}, update_document)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def startup_db_client():
|
||||
# await update()
|
||||
await update()
|
||||
file_path = os.path.join(os.getcwd(), 'file')
|
||||
if not os.path.exists(file_path):
|
||||
os.makedirs(file_path)
|
||||
|
|
Loading…
Reference in New Issue