mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-03-28 17:43:05 +01:00
Make mark-all-read atomic
This commit is contained in:
@@ -223,6 +223,7 @@ class ContactRepository:
|
||||
async def mark_all_read(timestamp: int) -> None:
|
||||
"""Mark all contacts as read at the given timestamp."""
|
||||
await db.conn.execute("UPDATE contacts SET last_read_at = ?", (timestamp,))
|
||||
await db.conn.commit()
|
||||
|
||||
@staticmethod
|
||||
async def get_by_pubkey_first_byte(hex_byte: str) -> list[Contact]:
|
||||
@@ -314,6 +315,7 @@ class ChannelRepository:
|
||||
async def mark_all_read(timestamp: int) -> None:
|
||||
"""Mark all channels as read at the given timestamp."""
|
||||
await db.conn.execute("UPDATE channels SET last_read_at = ?", (timestamp,))
|
||||
await db.conn.commit()
|
||||
|
||||
|
||||
class MessageRepository:
|
||||
|
||||
@@ -5,7 +5,6 @@ import time
|
||||
|
||||
from fastapi import APIRouter, Query
|
||||
|
||||
from app.database import db
|
||||
from app.models import UnreadCounts
|
||||
from app.repository import ChannelRepository, ContactRepository, MessageRepository
|
||||
|
||||
@@ -37,7 +36,6 @@ async def mark_all_read() -> dict:
|
||||
|
||||
await ContactRepository.mark_all_read(now)
|
||||
await ChannelRepository.mark_all_read(now)
|
||||
await db.conn.commit()
|
||||
|
||||
logger.info("Marked all contacts and channels as read at %d", now)
|
||||
return {"status": "ok", "timestamp": now}
|
||||
|
||||
Reference in New Issue
Block a user