def _message_counts(message_path: Path) -> tuple[int, int]:
    revision = _database_revision(message_path)
    def build():
        connection = connect_sqlite(str(message_path))
        try:
            columns = _columns(connection, "message_table")
            if "conversation_id" not in columns:
                return _count(connection, "message_table"), 0
            values = connection.execute(
                "SELECT COUNT(*),COUNT(DISTINCT CASE WHEN conversation_id IS NOT NULL "
                "AND conversation_id<>'' AND conversation_id NOT LIKE 'Y:%' "
                "THEN conversation_id END) FROM message_table"
            ).fetchone()
            return int(values[0]), int(values[1])
        finally:
            connection.close()
    return _cached("counts", revision[0], revision, build)


