perf(hub): cache the names directory, share state builds, retry stations
Concurrent /api/state polls share one build through LiveState for a short TTL, and every POST and PATCH invalidates it, so a write is never followed by a stale view. The names directory is cached, the first transcript scan reads outside the hub lock, the graph timeline starts at the window begin, and unresolved radio stations are retried on a daemon thread every RETRY_SECONDS instead of failing until restart. 🎯 Fix: 85 % 💥 Break: 8 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 78 🚦 Gate: ⛔ fix 85 % < 90, break 8 % > 5 Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6c63c364bd
commit
96d4d2933c
18 files changed
+299
-32
No files matched your search
@@ -27,5 +27,37 @@ class TestRenameOnce(unittest.TestCase):
|
||||
self.assertEqual([row["title"] for row in names.Directory(entries).renames(0, 10)], ["A is now called B", "B is now called A"])
|
||||
|
||||
|
||||
def flips(count: int) -> list[dict]:
|
||||
return [{"session": "s1", "name": "AB"[index % 2], "first_seen": float(index), "source": "claim"} for index in range(count)]
|
||||
|
||||
|
||||
class TestDirectoryLookups(unittest.TestCase):
|
||||
def test_at_names_the_last_entry_seen_at_or_before_the_moment_and_the_first_one_before_any(self):
|
||||
directory = names.Directory(flips(6))
|
||||
scanned = flips(6)
|
||||
for ts in (-1.0, 0.0, 0.5, 1.0, 2.9, 3.0, 5.0, 99.0):
|
||||
valid = [entry for entry in scanned if entry["first_seen"] <= ts]
|
||||
self.assertEqual(directory.at("s1", ts), (valid[-1] if valid else scanned[0])["name"], ts)
|
||||
self.assertEqual(directory.at("s9", 1.0), "")
|
||||
|
||||
def test_a_windowed_timeline_keeps_the_birth_and_every_name_from_the_last_one_before_the_window(self):
|
||||
directory = names.Directory(flips(10))
|
||||
self.assertEqual([entry["since"] for entry in directory.timeline("s1", 6.5)], [0.0, 6.0, 7.0, 8.0, 9.0])
|
||||
self.assertEqual(directory.timeline("s1", -5.0), directory.timeline("s1"))
|
||||
self.assertEqual(directory.timeline("s1", 0.0), directory.timeline("s1"))
|
||||
self.assertEqual(directory.timeline("s9", 3.0), [])
|
||||
|
||||
def test_the_directory_is_rebuilt_only_after_a_new_entry(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
book = names.Names(Path(folder) / "names.json")
|
||||
book.observe([("s1", "A", 1.0, "claim")], 10.0)
|
||||
first = book.directory()
|
||||
book.observe([("s1", "A", 2.0, "claim")], 20.0)
|
||||
self.assertIs(book.directory(), first)
|
||||
book.observe([("s1", "B", 3.0, "claim")], 30.0)
|
||||
self.assertIsNot(book.directory(), first)
|
||||
self.assertEqual(book.directory().now("s1"), "B")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user