Skip to content

Commit 0ddfb61

Browse files
authored
Speeds up case resolution (Netflix#5384)
* Speeds up case resolution * bumps pre commit versions
1 parent 0997901 commit 0ddfb61

File tree

3 files changed

+29
-38
lines changed

3 files changed

+29
-38
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ default_language_version:
1515
repos:
1616
- repo: https://github.com/astral-sh/ruff-pre-commit
1717
# ruff version.
18-
rev: v0.6.4
18+
rev: v0.7.0
1919
hooks:
2020
# Run the linter.
2121
#
@@ -28,7 +28,7 @@ repos:
2828

2929
# Typos
3030
- repo: https://github.com/crate-ci/typos
31-
rev: v1.24.5
31+
rev: v1.26.1
3232
hooks:
3333
- id: typos
3434
exclude: ^(data/dispatch-sample-data.dump|src/dispatch/static/dispatch/src/|src/dispatch/database/revisions/)

src/dispatch/case/flows.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,34 @@
1111
from dispatch.database.core import SessionLocal
1212
from dispatch.decorators import background_task
1313
from dispatch.document import flows as document_flows
14-
from dispatch.enums import DocumentResourceTypes, Visibility, EventType
14+
from dispatch.enums import DocumentResourceTypes, EventType, Visibility
1515
from dispatch.event import service as event_service
1616
from dispatch.group import flows as group_flows
1717
from dispatch.group.enums import GroupAction, GroupType
1818
from dispatch.incident import flows as incident_flows
1919
from dispatch.incident import service as incident_service
2020
from dispatch.incident.enums import IncidentStatus
2121
from dispatch.incident.messaging import send_participant_announcement_message
22-
from dispatch.incident.models import IncidentCreate, Incident
23-
from dispatch.incident.type.models import IncidentType
22+
from dispatch.incident.models import Incident, IncidentCreate
2423
from dispatch.incident.priority.models import IncidentPriority
24+
from dispatch.incident.type.models import IncidentType
2525
from dispatch.individual.models import IndividualContactRead
2626
from dispatch.models import OrganizationSlug, PrimaryKey
2727
from dispatch.participant import flows as participant_flows
2828
from dispatch.participant import service as participant_service
2929
from dispatch.participant.models import ParticipantUpdate
3030
from dispatch.participant_role import flows as role_flow
31-
from dispatch.participant_role.models import ParticipantRoleType, ParticipantRole
31+
from dispatch.participant_role.models import ParticipantRole, ParticipantRoleType
3232
from dispatch.plugin import service as plugin_service
3333
from dispatch.storage import flows as storage_flows
3434
from dispatch.storage.enums import StorageAction
3535
from dispatch.ticket import flows as ticket_flows
3636

3737
from .messaging import (
3838
send_case_created_notifications,
39-
send_case_update_notifications,
4039
send_case_rating_feedback_message,
40+
send_case_update_notifications,
4141
)
42-
4342
from .models import Case, CaseStatus
4443
from .service import get
4544

@@ -337,17 +336,17 @@ def case_update_flow(
337336
# we get the case
338337
case = get(db_session=db_session, case_id=case_id)
339338

340-
if reporter_email:
341-
# we run the case assign role flow for the reporter
339+
if reporter_email and case and reporter_email != case.reporter.email:
340+
# we run the case assign role flow for the reporter if it changed
342341
case_assign_role_flow(
343342
case_id=case.id,
344343
participant_email=reporter_email,
345344
participant_role=ParticipantRoleType.reporter,
346345
db_session=db_session,
347346
)
348347

349-
if assignee_email:
350-
# we run the case assign role flow for the assignee
348+
if assignee_email and case and assignee_email != case.assignee.email:
349+
# we run the case assign role flow for the assignee if it changed
351350
case_assign_role_flow(
352351
case_id=case.id,
353352
participant_email=assignee_email,
@@ -375,15 +374,15 @@ def case_update_flow(
375374

376375
if case.tactical_group:
377376
# we update the tactical group
378-
if reporter_email:
377+
if reporter_email and reporter_email != case.reporter.email:
379378
group_flows.update_group(
380379
subject=case,
381380
group=case.tactical_group,
382381
group_action=GroupAction.add_member,
383382
group_member=reporter_email,
384383
db_session=db_session,
385384
)
386-
if assignee_email:
385+
if assignee_email and assignee_email != case.assignee.email:
387386
group_flows.update_group(
388387
subject=case,
389388
group=case.tactical_group,

src/dispatch/plugins/dispatch_slack/case/interactive.py

+16-24
Original file line numberDiff line numberDiff line change
@@ -1660,49 +1660,41 @@ def handle_resolve_submission_event(
16601660
user: DispatchUser,
16611661
):
16621662
ack()
1663-
# we get the current or previous case
1664-
case = case_service.get(db_session=db_session, case_id=context["subject"].id)
1665-
previous_case = CaseRead.from_orm(case)
1663+
# we get the current case and store it as previous case
1664+
current_case = case_service.get(db_session=db_session, case_id=context["subject"].id)
1665+
previous_case = CaseRead.from_orm(current_case)
16661666

1667-
# we run the case status transition flow
1668-
case_flows.case_status_transition_flow_dispatcher(
1669-
case=case,
1670-
current_status=CaseStatus.closed,
1671-
db_session=db_session,
1672-
previous_status=case.status,
1673-
organization_slug=context["subject"].organization_slug,
1674-
)
1675-
1676-
# we update the case with the new resolution and status
1667+
# we update the case with the new resolution, resolution reason and status
16771668
case_in = CaseUpdate(
1678-
title=case.title,
1669+
title=current_case.title,
16791670
resolution_reason=form_data[DefaultBlockIds.case_resolution_reason_select]["value"],
16801671
resolution=form_data[DefaultBlockIds.resolution_input],
1681-
visibility=case.visibility,
1672+
visibility=current_case.visibility,
16821673
status=CaseStatus.closed,
16831674
)
1684-
case = case_service.update(
1675+
updated_case = case_service.update(
16851676
db_session=db_session,
1686-
case=case,
1677+
case=current_case,
16871678
case_in=case_in,
16881679
current_user=user,
16891680
)
16901681

1682+
# we run the case update flow
16911683
case_flows.case_update_flow(
1692-
case_id=case.id,
1684+
case_id=updated_case.id,
16931685
previous_case=previous_case,
16941686
db_session=db_session,
1695-
reporter_email=case.reporter.individual.email if case.reporter else None,
1696-
assignee_email=case.assignee.individual.email if case.assignee else None,
1687+
reporter_email=updated_case.reporter.individual.email if updated_case.reporter else None,
1688+
assignee_email=updated_case.assignee.individual.email if updated_case.assignee else None,
16971689
organization_slug=context["subject"].organization_slug,
16981690
)
16991691

1700-
# We update the case message with the new resolution and status
1701-
blocks = create_case_message(case=case, channel_id=context["subject"].channel_id)
1692+
# we update the case notification with the resolution, resolution reason and status
1693+
blocks = create_case_message(case=updated_case, channel_id=context["subject"].channel_id)
17021694
client.chat_update(
17031695
blocks=blocks,
1704-
ts=case.conversation.thread_id,
1705-
channel=case.conversation.channel_id,
1696+
ts=updated_case.conversation.thread_id,
1697+
channel=updated_case.conversation.channel_id,
17061698
)
17071699

17081700

0 commit comments

Comments
 (0)