Process 1 build 0803262038
This commit is contained in:
@@ -362,7 +362,13 @@ def init_db() -> None:
|
||||
external_ref TEXT,
|
||||
source_system TEXT,
|
||||
source_request_id INTEGER,
|
||||
related_item_id INTEGER,
|
||||
status TEXT NOT NULL,
|
||||
workflow_request_status TEXT,
|
||||
workflow_media_status TEXT,
|
||||
issue_type TEXT,
|
||||
issue_resolved_at TEXT,
|
||||
metadata_json TEXT,
|
||||
priority TEXT NOT NULL,
|
||||
created_by_username TEXT NOT NULL,
|
||||
created_by_id INTEGER,
|
||||
@@ -465,6 +471,24 @@ def init_db() -> None:
|
||||
ON portal_items (status, updated_at DESC, id DESC)
|
||||
"""
|
||||
)
|
||||
try:
|
||||
conn.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_portal_items_workflow
|
||||
ON portal_items (kind, workflow_request_status, workflow_media_status, updated_at DESC, id DESC)
|
||||
"""
|
||||
)
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
conn.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_portal_items_related_item
|
||||
ON portal_items (related_item_id, updated_at DESC, id DESC)
|
||||
"""
|
||||
)
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
conn.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_portal_comments_item_created
|
||||
@@ -553,6 +577,48 @@ def init_db() -> None:
|
||||
conn.execute("ALTER TABLE signup_invites ADD COLUMN recipient_email TEXT")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
conn.execute("ALTER TABLE portal_items ADD COLUMN related_item_id INTEGER")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
conn.execute("ALTER TABLE portal_items ADD COLUMN workflow_request_status TEXT")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
conn.execute("ALTER TABLE portal_items ADD COLUMN workflow_media_status TEXT")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
conn.execute("ALTER TABLE portal_items ADD COLUMN issue_type TEXT")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
conn.execute("ALTER TABLE portal_items ADD COLUMN issue_resolved_at TEXT")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
conn.execute("ALTER TABLE portal_items ADD COLUMN metadata_json TEXT")
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
conn.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_portal_items_workflow
|
||||
ON portal_items (kind, workflow_request_status, workflow_media_status, updated_at DESC, id DESC)
|
||||
"""
|
||||
)
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
conn.execute(
|
||||
"""
|
||||
CREATE INDEX IF NOT EXISTS idx_portal_items_related_item
|
||||
ON portal_items (related_item_id, updated_at DESC, id DESC)
|
||||
"""
|
||||
)
|
||||
except sqlite3.OperationalError:
|
||||
pass
|
||||
try:
|
||||
conn.execute(
|
||||
"""
|
||||
@@ -2952,14 +3018,20 @@ def _portal_item_from_row(row: tuple[Any, ...]) -> Dict[str, Any]:
|
||||
"external_ref": row[6],
|
||||
"source_system": row[7],
|
||||
"source_request_id": row[8],
|
||||
"status": row[9],
|
||||
"priority": row[10],
|
||||
"created_by_username": row[11],
|
||||
"created_by_id": row[12],
|
||||
"assignee_username": row[13],
|
||||
"created_at": row[14],
|
||||
"updated_at": row[15],
|
||||
"last_activity_at": row[16],
|
||||
"related_item_id": row[9],
|
||||
"status": row[10],
|
||||
"workflow_request_status": row[11],
|
||||
"workflow_media_status": row[12],
|
||||
"issue_type": row[13],
|
||||
"issue_resolved_at": row[14],
|
||||
"metadata_json": row[15],
|
||||
"priority": row[16],
|
||||
"created_by_username": row[17],
|
||||
"created_by_id": row[18],
|
||||
"assignee_username": row[19],
|
||||
"created_at": row[20],
|
||||
"updated_at": row[21],
|
||||
"last_activity_at": row[22],
|
||||
}
|
||||
|
||||
|
||||
@@ -2987,7 +3059,13 @@ def create_portal_item(
|
||||
external_ref: Optional[str] = None,
|
||||
source_system: Optional[str] = None,
|
||||
source_request_id: Optional[int] = None,
|
||||
related_item_id: Optional[int] = None,
|
||||
status: str = "new",
|
||||
workflow_request_status: Optional[str] = None,
|
||||
workflow_media_status: Optional[str] = None,
|
||||
issue_type: Optional[str] = None,
|
||||
issue_resolved_at: Optional[str] = None,
|
||||
metadata_json: Optional[str] = None,
|
||||
priority: str = "normal",
|
||||
assignee_username: Optional[str] = None,
|
||||
) -> Dict[str, Any]:
|
||||
@@ -3004,7 +3082,13 @@ def create_portal_item(
|
||||
external_ref,
|
||||
source_system,
|
||||
source_request_id,
|
||||
related_item_id,
|
||||
status,
|
||||
workflow_request_status,
|
||||
workflow_media_status,
|
||||
issue_type,
|
||||
issue_resolved_at,
|
||||
metadata_json,
|
||||
priority,
|
||||
created_by_username,
|
||||
created_by_id,
|
||||
@@ -3013,7 +3097,7 @@ def create_portal_item(
|
||||
updated_at,
|
||||
last_activity_at
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
(
|
||||
kind,
|
||||
@@ -3024,7 +3108,13 @@ def create_portal_item(
|
||||
external_ref,
|
||||
source_system,
|
||||
source_request_id,
|
||||
related_item_id,
|
||||
status,
|
||||
workflow_request_status,
|
||||
workflow_media_status,
|
||||
issue_type,
|
||||
issue_resolved_at,
|
||||
metadata_json,
|
||||
priority,
|
||||
created_by_username,
|
||||
created_by_id,
|
||||
@@ -3063,7 +3153,13 @@ def get_portal_item(item_id: int) -> Optional[Dict[str, Any]]:
|
||||
external_ref,
|
||||
source_system,
|
||||
source_request_id,
|
||||
related_item_id,
|
||||
status,
|
||||
workflow_request_status,
|
||||
workflow_media_status,
|
||||
issue_type,
|
||||
issue_resolved_at,
|
||||
metadata_json,
|
||||
priority,
|
||||
created_by_username,
|
||||
created_by_id,
|
||||
@@ -3083,6 +3179,11 @@ def list_portal_items(
|
||||
*,
|
||||
kind: Optional[str] = None,
|
||||
status: Optional[str] = None,
|
||||
workflow_request_status: Optional[str] = None,
|
||||
workflow_media_status: Optional[str] = None,
|
||||
source_system: Optional[str] = None,
|
||||
source_request_id: Optional[int] = None,
|
||||
related_item_id: Optional[int] = None,
|
||||
mine_username: Optional[str] = None,
|
||||
search: Optional[str] = None,
|
||||
limit: int = 100,
|
||||
@@ -3096,6 +3197,21 @@ def list_portal_items(
|
||||
if isinstance(status, str) and status.strip():
|
||||
clauses.append("status = ?")
|
||||
params.append(status.strip().lower())
|
||||
if isinstance(workflow_request_status, str) and workflow_request_status.strip():
|
||||
clauses.append("workflow_request_status = ?")
|
||||
params.append(workflow_request_status.strip().lower())
|
||||
if isinstance(workflow_media_status, str) and workflow_media_status.strip():
|
||||
clauses.append("workflow_media_status = ?")
|
||||
params.append(workflow_media_status.strip().lower())
|
||||
if isinstance(source_system, str) and source_system.strip():
|
||||
clauses.append("source_system = ?")
|
||||
params.append(source_system.strip().lower())
|
||||
if isinstance(source_request_id, int):
|
||||
clauses.append("source_request_id = ?")
|
||||
params.append(source_request_id)
|
||||
if isinstance(related_item_id, int):
|
||||
clauses.append("related_item_id = ?")
|
||||
params.append(related_item_id)
|
||||
if isinstance(mine_username, str) and mine_username.strip():
|
||||
clauses.append("created_by_username = ?")
|
||||
params.append(mine_username.strip())
|
||||
@@ -3120,7 +3236,13 @@ def list_portal_items(
|
||||
external_ref,
|
||||
source_system,
|
||||
source_request_id,
|
||||
related_item_id,
|
||||
status,
|
||||
workflow_request_status,
|
||||
workflow_media_status,
|
||||
issue_type,
|
||||
issue_resolved_at,
|
||||
metadata_json,
|
||||
priority,
|
||||
created_by_username,
|
||||
created_by_id,
|
||||
@@ -3142,6 +3264,11 @@ def count_portal_items(
|
||||
*,
|
||||
kind: Optional[str] = None,
|
||||
status: Optional[str] = None,
|
||||
workflow_request_status: Optional[str] = None,
|
||||
workflow_media_status: Optional[str] = None,
|
||||
source_system: Optional[str] = None,
|
||||
source_request_id: Optional[int] = None,
|
||||
related_item_id: Optional[int] = None,
|
||||
mine_username: Optional[str] = None,
|
||||
search: Optional[str] = None,
|
||||
) -> int:
|
||||
@@ -3153,6 +3280,21 @@ def count_portal_items(
|
||||
if isinstance(status, str) and status.strip():
|
||||
clauses.append("status = ?")
|
||||
params.append(status.strip().lower())
|
||||
if isinstance(workflow_request_status, str) and workflow_request_status.strip():
|
||||
clauses.append("workflow_request_status = ?")
|
||||
params.append(workflow_request_status.strip().lower())
|
||||
if isinstance(workflow_media_status, str) and workflow_media_status.strip():
|
||||
clauses.append("workflow_media_status = ?")
|
||||
params.append(workflow_media_status.strip().lower())
|
||||
if isinstance(source_system, str) and source_system.strip():
|
||||
clauses.append("source_system = ?")
|
||||
params.append(source_system.strip().lower())
|
||||
if isinstance(source_request_id, int):
|
||||
clauses.append("source_request_id = ?")
|
||||
params.append(source_request_id)
|
||||
if isinstance(related_item_id, int):
|
||||
clauses.append("related_item_id = ?")
|
||||
params.append(related_item_id)
|
||||
if isinstance(mine_username, str) and mine_username.strip():
|
||||
clauses.append("created_by_username = ?")
|
||||
params.append(mine_username.strip())
|
||||
@@ -3182,6 +3324,12 @@ def update_portal_item(
|
||||
external_ref: Any = _DB_UNSET,
|
||||
source_system: Any = _DB_UNSET,
|
||||
source_request_id: Any = _DB_UNSET,
|
||||
related_item_id: Any = _DB_UNSET,
|
||||
workflow_request_status: Any = _DB_UNSET,
|
||||
workflow_media_status: Any = _DB_UNSET,
|
||||
issue_type: Any = _DB_UNSET,
|
||||
issue_resolved_at: Any = _DB_UNSET,
|
||||
metadata_json: Any = _DB_UNSET,
|
||||
) -> Optional[Dict[str, Any]]:
|
||||
updates: list[str] = []
|
||||
params: list[Any] = []
|
||||
@@ -3215,6 +3363,24 @@ def update_portal_item(
|
||||
if source_request_id is not _DB_UNSET:
|
||||
updates.append("source_request_id = ?")
|
||||
params.append(source_request_id)
|
||||
if related_item_id is not _DB_UNSET:
|
||||
updates.append("related_item_id = ?")
|
||||
params.append(related_item_id)
|
||||
if workflow_request_status is not _DB_UNSET:
|
||||
updates.append("workflow_request_status = ?")
|
||||
params.append(workflow_request_status)
|
||||
if workflow_media_status is not _DB_UNSET:
|
||||
updates.append("workflow_media_status = ?")
|
||||
params.append(workflow_media_status)
|
||||
if issue_type is not _DB_UNSET:
|
||||
updates.append("issue_type = ?")
|
||||
params.append(issue_type)
|
||||
if issue_resolved_at is not _DB_UNSET:
|
||||
updates.append("issue_resolved_at = ?")
|
||||
params.append(issue_resolved_at)
|
||||
if metadata_json is not _DB_UNSET:
|
||||
updates.append("metadata_json = ?")
|
||||
params.append(metadata_json)
|
||||
if not updates:
|
||||
return get_portal_item(item_id)
|
||||
now = datetime.now(timezone.utc).isoformat()
|
||||
@@ -3342,13 +3508,31 @@ def get_portal_overview() -> Dict[str, Any]:
|
||||
GROUP BY status
|
||||
"""
|
||||
).fetchall()
|
||||
request_workflow_rows = conn.execute(
|
||||
"""
|
||||
SELECT
|
||||
COALESCE(workflow_request_status, ''),
|
||||
COALESCE(workflow_media_status, ''),
|
||||
COUNT(*)
|
||||
FROM portal_items
|
||||
WHERE kind = 'request'
|
||||
GROUP BY workflow_request_status, workflow_media_status
|
||||
"""
|
||||
).fetchall()
|
||||
total_items_row = conn.execute("SELECT COUNT(*) FROM portal_items").fetchone()
|
||||
total_comments_row = conn.execute("SELECT COUNT(*) FROM portal_comments").fetchone()
|
||||
request_workflow: Dict[str, Dict[str, int]] = {}
|
||||
for row in request_workflow_rows:
|
||||
request_status = str(row[0] or "")
|
||||
media_status = str(row[1] or "")
|
||||
request_workflow.setdefault(request_status, {})
|
||||
request_workflow[request_status][media_status] = int(row[2] or 0)
|
||||
return {
|
||||
"total_items": int(total_items_row[0] or 0) if total_items_row else 0,
|
||||
"total_comments": int(total_comments_row[0] or 0) if total_comments_row else 0,
|
||||
"by_kind": {str(row[0]): int(row[1] or 0) for row in kind_rows},
|
||||
"by_status": {str(row[0]): int(row[1] or 0) for row in status_rows},
|
||||
"request_workflow": request_workflow,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user