First wave of work

This commit is contained in:
Jack Kingsman
2026-03-06 17:41:37 -08:00
parent b5e2a4c269
commit 9c54ea623e
18 changed files with 256 additions and 42 deletions
+10 -3
View File
@@ -26,6 +26,7 @@ class MessageRepository:
conversation_key: str,
sender_timestamp: int | None = None,
path: str | None = None,
path_len: int | None = None,
txt_type: int = 0,
signature: str | None = None,
outgoing: bool = False,
@@ -43,7 +44,10 @@ class MessageRepository:
# Convert single path to paths array format
paths_json = None
if path is not None:
paths_json = json.dumps([{"path": path, "received_at": received_at}])
normalized_path_len = path_len if isinstance(path_len, int) else len(path) // 2
path_entry: dict[str, Any] = {"path": path, "received_at": received_at}
path_entry["path_len"] = normalized_path_len
paths_json = json.dumps([path_entry])
cursor = await db.conn.execute(
"""
@@ -74,7 +78,7 @@ class MessageRepository:
@staticmethod
async def add_path(
message_id: int, path: str, received_at: int | None = None
message_id: int, path: str, received_at: int | None = None, path_len: int | None = None
) -> list[MessagePath]:
"""Add a new path to an existing message.
@@ -85,7 +89,10 @@ class MessageRepository:
# Atomic append: use json_insert to avoid read-modify-write race when
# multiple duplicate packets arrive concurrently for the same message.
new_entry = json.dumps({"path": path, "received_at": ts})
normalized_path_len = path_len if isinstance(path_len, int) else len(path) // 2
new_entry_dict: dict[str, Any] = {"path": path, "received_at": ts}
new_entry_dict["path_len"] = normalized_path_len
new_entry = json.dumps(new_entry_dict)
await db.conn.execute(
"""UPDATE messages SET paths = json_insert(
COALESCE(paths, '[]'), '$[#]', json(?)