aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/chat/store.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/chat/store.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/chat/store.py32
1 files changed, 12 insertions, 20 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/chat/store.py b/packages/meshbay-node/src/meshbay_node/chat/store.py
index 9e07aff..7610b33 100644
--- a/packages/meshbay-node/src/meshbay_node/chat/store.py
+++ b/packages/meshbay-node/src/meshbay_node/chat/store.py
@@ -54,8 +54,11 @@ CREATE TABLE IF NOT EXISTS messages (
sender_name TEXT DEFAULT ''
);
CREATE INDEX IF NOT EXISTS idx_messages_ts ON messages(timestamp);
-CREATE INDEX IF NOT EXISTS idx_messages_thread ON messages(thread_id);
"""
+# `thread_id` is written and read by nothing: chat has no threads. The column
+# stays, empty, because a node downgraded to an older version names it in every
+# query, and its rows must keep opening. Its index goes; an older node makes it
+# again on its own.
# Additive, every one with a default, so an existing chat.db opens unchanged and
# a node that is downgraded still reads its own rows. `CREATE TABLE IF NOT
@@ -88,7 +91,6 @@ class StoredMessage:
iteration: int
payload: bytes
timestamp: float
- thread_id: str | None
sender_name: str = ""
format: int = FORMAT_PLAIN
epoch: int = 0
@@ -97,16 +99,16 @@ class StoredMessage:
sig: bytes | None = None
-_COLUMNS = ("id, sender_id, iteration, payload, timestamp, thread_id, "
+_COLUMNS = ("id, sender_id, iteration, payload, timestamp, "
"sender_name, format, epoch, device, nonce, sig")
def _row(r) -> StoredMessage:
return StoredMessage(
id=r[0], sender_id=r[1], iteration=r[2], payload=r[3],
- timestamp=r[4], thread_id=r[5], sender_name=r[6] or "",
- format=r[7] or FORMAT_PLAIN, epoch=r[8] or 0,
- device=r[9], nonce=r[10], sig=r[11],
+ timestamp=r[4], sender_name=r[5] or "",
+ format=r[6] or FORMAT_PLAIN, epoch=r[7] or 0,
+ device=r[8], nonce=r[9], sig=r[10],
)
@@ -132,6 +134,7 @@ class ChatStore:
# nothing to show for it.
pass
await self._db.execute(_REPLAY_INDEX)
+ await self._db.execute("DROP INDEX IF EXISTS idx_messages_thread")
await self._db.commit()
async def close(self) -> None:
@@ -151,7 +154,6 @@ class ChatStore:
sender_id: str,
iteration: int,
payload: bytes,
- thread_id: str | None = None,
sender_name: str = "",
*,
format: int = FORMAT_PLAIN,
@@ -171,9 +173,9 @@ class ChatStore:
try:
cursor = await self._db.execute(
"INSERT INTO messages (sender_id, iteration, payload, timestamp, "
- " thread_id, sender_name, format, epoch, device, nonce, sig) "
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
- (sender_id, iteration, payload, ts, thread_id, sender_name,
+ " sender_name, format, epoch, device, nonce, sig) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ (sender_id, iteration, payload, ts, sender_name,
format, epoch, device, nonce, sig),
)
except aiosqlite.IntegrityError as e:
@@ -234,16 +236,6 @@ class ChatStore:
"SELECT 1 FROM messages WHERE id < ? LIMIT 1", (message_id,))
return await cursor.fetchone() is not None
- async def get_thread(self, thread_id: str, limit: int = 100) -> list[StoredMessage]:
- """Get messages in a thread."""
- cursor = await self._db.execute(
- f"SELECT {_COLUMNS} "
- "FROM messages WHERE thread_id = ? ORDER BY timestamp ASC LIMIT ?",
- (thread_id, limit),
- )
- rows = await cursor.fetchall()
- return [_row(r) for r in rows]
-
@property
def db_path(self) -> Path:
"""Where this store lives — the re-encryption command backs it up."""