Add source-linked inline comparison for uploaded estimates
This commit is contained in:
@@ -702,6 +702,42 @@ def replace_scoped_norm_quote(username: str, tab_id: str, quote_id: int,
|
||||
return cursor.rowcount == 1
|
||||
|
||||
|
||||
def get_linked_file_compare(username: str, tab_id: str, compare_id: int) -> dict | None:
|
||||
"""Return a saved file comparison only with its answer in the same dialog."""
|
||||
import json
|
||||
|
||||
with _conn() as conn:
|
||||
row = conn.execute(
|
||||
"SELECT content FROM messages WHERE id=? AND username=? AND tab_id=? "
|
||||
"AND role='file_compare'", (compare_id, username, tab_id),
|
||||
).fetchone()
|
||||
if row is None:
|
||||
return None
|
||||
try:
|
||||
data = json.loads(row["content"])
|
||||
assistant_id = data["_assistant_id"]
|
||||
except (ValueError, KeyError, TypeError):
|
||||
return None
|
||||
answer = conn.execute(
|
||||
"SELECT 1 FROM messages WHERE id=? AND username=? AND tab_id=? AND role='assistant'",
|
||||
(assistant_id, username, tab_id),
|
||||
).fetchone()
|
||||
return {"raw": row["content"], "data": data} if answer else None
|
||||
|
||||
|
||||
def replace_linked_file_compare(username: str, tab_id: str, compare_id: int,
|
||||
old_content: str, new_content: str) -> bool:
|
||||
"""Atomically reject concurrent edits to a comparison in the current dialog."""
|
||||
with _conn() as conn:
|
||||
conn.execute("BEGIN IMMEDIATE")
|
||||
cursor = conn.execute(
|
||||
"UPDATE messages SET content=? WHERE id=? AND username=? AND tab_id=? "
|
||||
"AND role='file_compare' AND content=?",
|
||||
(new_content, compare_id, username, tab_id, old_content),
|
||||
)
|
||||
return cursor.rowcount == 1
|
||||
|
||||
|
||||
def replace_linked_estimate(username: str, tab_id: str, estimate_id: int,
|
||||
expected_revision: int, data: dict, answer: str) -> str:
|
||||
"""Compare-and-swap answer and estimate in one SQLite transaction."""
|
||||
|
||||
Reference in New Issue
Block a user