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

feature: openapi单据创建性能优化 #1244

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
6 changes: 5 additions & 1 deletion itsm/component/misc_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ def can(self, request):
if not request_paths:
return True
for path in request_paths:
if path["path"] == request.path and request.method in path["method"]:
if (
path["path"] == request.path
and request.method in path["method"]
and "profile" in request.GET
):
return True

def process_view(self, request, callback, callback_args, callback_kwargs):
Expand Down
18 changes: 18 additions & 0 deletions itsm/openapi/ticket/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from celery.task import task
from common.log import logger


@task
def openapi_start_ticket(ticket, fields, from_ticket_id=None):
try:
logger.info(
"[openapi_start_ticket] Start ticket, ticket id = {}".format(ticket.id)
)
ticket.do_after_create(fields, from_ticket_id)
ticket.start()
except Exception as e:
logger.exception(
"[openapi_start_ticket_error] Exception occurred, error message: {}, fields={}".format(
e, fields
)
)
7 changes: 3 additions & 4 deletions itsm/openapi/ticket/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
TicketComplexLogsSerializer,
TicketApproveSerializer,
)
from itsm.openapi.ticket.tasks import openapi_start_ticket
from itsm.openapi.ticket.utils import edit_ticket_field
from itsm.openapi.ticket.validators import (
openapi_operate_validate,
Expand All @@ -92,7 +93,6 @@
Status,
)
from itsm.ticket.serializers import TicketList, TicketSerializer
from itsm.ticket.tasks import start_pipeline
from itsm.ticket.validators import (
terminate_validate,
withdraw_validate,
Expand Down Expand Up @@ -414,10 +414,9 @@ def create_ticket(self, request):
try:
# 创建额外的全局字段
instance.create_dynamic_fields(dynamic_fields)
instance.do_after_create(
data["fields"], request.data.get("from_ticket_id", None)
openapi_start_ticket.apply_async(
[instance, data["fields"], request.data.get("from_ticket_id", None)]
)
start_pipeline.apply_async([instance])
except Exception as e:
logger.exception(
"[openapi][create_ticket]-> 单据创建失败, 错误原因 error={}".format(e)
Expand Down
Loading