thanks for this great stuff, may I suggest few things #86

Open
opened 2026-10-05 03:20:29 +02:00 by adam · 1 comment
Owner

Hello, thanks for this great stuff, may I suggest few things :

improvments :

async management

main loop :

import asyncio

async def main():
    await asyncio.gather(
        run_ui(),
        run_meshtastic(),
        db_worker()
    )

asyncio.run(main())

Queue DB :

import asyncio

db_queue = asyncio.Queue()

async def db_worker():
    while True:
        query, params = await db_queue.get()
        execute_sql(query, params)
        db_queue.task_done()

SQLite optimisation :

def init_db(conn):
    conn.execute("PRAGMA journal_mode=WAL;")
    conn.execute("PRAGMA synchronous=NORMAL;")

    conn.execute("""
    CREATE INDEX IF NOT EXISTS idx_msg_time 
    ON messages(timestamp);
    """)

    conn.execute("""
    CREATE INDEX IF NOT EXISTS idx_msg_node 
    ON messages(node_id);
    """)

Full text search (FTS5)

CREATE VIRTUAL TABLE messages_fts USING fts5(content, node_id);

INSERT INTO messages_fts(content, node_id)
SELECT content, node_id FROM messages;

Auto reconnect Meshtatic :

import asyncio

async def connect_loop():
    delay = 1
    while True:
        try:
            await connect_meshtastic()
            delay = 1
        except Exception:
            await asyncio.sleep(delay)
            delay = min(delay * 2, 60)

Cache nodes :

nodes_cache = {}

def update_node(node):
    nodes_cache[node["id"]] = node

def get_node(node_id):
    return nodes_cache.get(node_id)

faster Ui :
versus screen.clear(), use :

window.addstr(y, x, new_text)
window.refresh()

code.rtf

Hello, thanks for this great stuff, may I suggest few things : improvments : async management main loop : ``` import asyncio async def main(): await asyncio.gather( run_ui(), run_meshtastic(), db_worker() ) asyncio.run(main()) ``` Queue DB : ``` import asyncio db_queue = asyncio.Queue() async def db_worker(): while True: query, params = await db_queue.get() execute_sql(query, params) db_queue.task_done() ``` SQLite optimisation : ``` def init_db(conn): conn.execute("PRAGMA journal_mode=WAL;") conn.execute("PRAGMA synchronous=NORMAL;") conn.execute(""" CREATE INDEX IF NOT EXISTS idx_msg_time ON messages(timestamp); """) conn.execute(""" CREATE INDEX IF NOT EXISTS idx_msg_node ON messages(node_id); """) ``` Full text search (FTS5) ``` CREATE VIRTUAL TABLE messages_fts USING fts5(content, node_id); INSERT INTO messages_fts(content, node_id) SELECT content, node_id FROM messages; ``` Auto reconnect Meshtatic : ``` import asyncio async def connect_loop(): delay = 1 while True: try: await connect_meshtastic() delay = 1 except Exception: await asyncio.sleep(delay) delay = min(delay * 2, 60) ``` Cache nodes : ``` nodes_cache = {} def update_node(node): nodes_cache[node["id"]] = node def get_node(node_id): return nodes_cache.get(node_id) ``` faster Ui : versus screen.clear(), use : ``` window.addstr(y, x, new_text) window.refresh() ``` ---- [code.rtf](https://github.com/user-attachments/files/27061589/code.rtf) <!-- github-sync-id:4324637104 -->
Author
Owner

Would you be able to submit a PR so I can test the changes?

Would you be able to submit a PR so I can test the changes? <!-- github-comment-id:4315219860 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/contact#86