FEAT - TASKER INCIDENT DIAGNOSTICS: compare UI primary and replica
This commit is contained in:
@@ -2,7 +2,7 @@ import re
|
||||
from html import escape
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.db import IntegrityError, connections, transaction
|
||||
from django.db.models import Count, Q
|
||||
from django.http import JsonResponse
|
||||
from django.utils import timezone
|
||||
@@ -165,6 +165,75 @@ def serialize_deleted_comment(comment, deletion_activity=None, include_body=Fals
|
||||
return serialized
|
||||
|
||||
|
||||
def comment_history_route_snapshot(project, issue_ids, owner_user_id, database_alias):
|
||||
active_comments = IssueComment.all_objects.using(database_alias).filter(
|
||||
project_id=project.id,
|
||||
issue_id__in=issue_ids,
|
||||
deleted_at__isnull=True,
|
||||
)
|
||||
ui_history_comments = IssueComment.objects.using(database_alias).filter(
|
||||
project_id=project.id,
|
||||
issue_id__in=issue_ids,
|
||||
project__project_projectmember__member_id=owner_user_id,
|
||||
project__project_projectmember__is_active=True,
|
||||
project__archived_at__isnull=True,
|
||||
workspace__slug=project.workspace.slug,
|
||||
)
|
||||
project_membership = (
|
||||
ProjectMember.all_objects.using(database_alias)
|
||||
.filter(
|
||||
project_id=project.id,
|
||||
member_id=owner_user_id,
|
||||
is_active=True,
|
||||
deleted_at__isnull=True,
|
||||
)
|
||||
.values("id", "role")
|
||||
.first()
|
||||
)
|
||||
return {
|
||||
"database_alias": database_alias,
|
||||
"active_comment_count": active_comments.count(),
|
||||
"ui_history_comment_count": ui_history_comments.count(),
|
||||
"active_project_membership": (
|
||||
{
|
||||
"id": str(project_membership["id"]),
|
||||
"role": project_membership["role"],
|
||||
}
|
||||
if project_membership is not None
|
||||
else None
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def comment_history_route_diagnostics(request, project, issue_ids):
|
||||
identity = get_agent_identity(request)
|
||||
owner_user_id = identity["owner_user_id"] if identity is not None else None
|
||||
if not owner_user_id:
|
||||
return {"ok": False, "error": "agent_owner_not_found"}
|
||||
|
||||
diagnostics = {
|
||||
"ok": True,
|
||||
"owner_user_id": owner_user_id,
|
||||
"primary": comment_history_route_snapshot(project, issue_ids, owner_user_id, "default"),
|
||||
"replica_configured": "replica" in connections.databases,
|
||||
"replica": None,
|
||||
}
|
||||
if diagnostics["replica_configured"]:
|
||||
try:
|
||||
diagnostics["replica"] = comment_history_route_snapshot(
|
||||
project,
|
||||
issue_ids,
|
||||
owner_user_id,
|
||||
"replica",
|
||||
)
|
||||
except Exception as error:
|
||||
diagnostics["replica"] = {
|
||||
"database_alias": "replica",
|
||||
"error": type(error).__name__,
|
||||
}
|
||||
return diagnostics
|
||||
|
||||
|
||||
def parse_comment_audit_integer(request, name, default, minimum, maximum):
|
||||
raw_value = request.GET.get(name)
|
||||
if raw_value in (None, ""):
|
||||
@@ -1195,6 +1264,11 @@ class NodeDCAgentProjectCommentAuditEndpoint(View):
|
||||
"limit": limit,
|
||||
"has_more": offset + len(deleted_page) < deleted_count,
|
||||
},
|
||||
"ui_history_route": comment_history_route_diagnostics(
|
||||
request,
|
||||
project,
|
||||
issue_ids,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user