Phase 3: Add path size inference and also bin some stupid migration tests while we're at it

This commit is contained in:
Jack Kingsman
2026-03-07 19:02:37 -08:00
parent e0d7c8a083
commit f97c846378
6 changed files with 35 additions and 46 deletions
+3 -1
View File
@@ -221,7 +221,9 @@ async def on_path_update(event: "Event") -> None:
)
return
await ContactRepository.update_path(contact.public_key, str(path), normalized_path_len)
await ContactRepository.update_path(
contact.public_key, str(path), normalized_path_len
)
async def on_new_contact(event: "Event") -> None:
+3
View File
@@ -2,6 +2,8 @@ from typing import Literal
from pydantic import BaseModel, Field
from app.path_utils import infer_hash_size
class Contact(BaseModel):
public_key: str = Field(description="Public key (64-char hex)")
@@ -32,6 +34,7 @@ class Contact(BaseModel):
"flags": self.flags,
"out_path": self.last_path or "",
"out_path_len": self.last_path_len,
"out_path_hash_mode": infer_hash_size(self.last_path or "", self.last_path_len) - 1,
"adv_lat": self.lat if self.lat is not None else 0.0,
"adv_lon": self.lon if self.lon is not None else 0.0,
"last_advert": self.last_advert if self.last_advert is not None else 0,
+7 -4
View File
@@ -25,8 +25,8 @@ class ContactRepository:
await db.conn.execute(
"""
INSERT INTO contacts (public_key, name, type, flags, last_path, last_path_len,
last_advert, lat, lon, last_seen, on_radio, last_contacted,
first_seen)
last_advert, lat, lon, last_seen,
on_radio, last_contacted, first_seen)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(public_key) DO UPDATE SET
name = COALESCE(excluded.name, contacts.name),
@@ -200,9 +200,12 @@ class ContactRepository:
return [ContactRepository._row_to_contact(row) for row in rows]
@staticmethod
async def update_path(public_key: str, path: str, path_len: int) -> None:
async def update_path(
public_key: str, path: str, path_len: int
) -> None:
await db.conn.execute(
"UPDATE contacts SET last_path = ?, last_path_len = ?, last_seen = ? WHERE public_key = ?",
"""UPDATE contacts SET last_path = ?, last_path_len = ?,
last_seen = ? WHERE public_key = ?""",
(path, path_len, int(time.time()), public_key.lower()),
)
await db.conn.commit()