Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Convert all namedtuples to attrs. #11665

Merged
merged 17 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1976,14 +1976,16 @@ def _store_retention_policy_for_room_txn(self, txn, event):
txn, self.store.get_retention_policy_for_room, (event.room_id,)
)

def store_event_search_txn(self, txn, event, key, value):
def store_event_search_txn(
self, txn, event: EventBase, key: str, value: str
clokep marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""Add event to the search table

Args:
txn (cursor):
event (EventBase):
key (str):
value (str):
txn:
event:
key:
value:
clokep marked this conversation as resolved.
Show resolved Hide resolved
"""
self.store.store_search_entries_txn(
txn,
Expand Down
16 changes: 11 additions & 5 deletions synapse/storage/databases/main/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

import logging
import re
from collections import namedtuple
from typing import TYPE_CHECKING, Collection, Iterable, List, Optional, Set

import attr

from synapse.api.errors import SynapseError
from synapse.events import EventBase
from synapse.storage._base import SQLBaseStore, db_to_json, make_in_list_sql_clause
Expand All @@ -33,10 +34,15 @@

logger = logging.getLogger(__name__)

SearchEntry = namedtuple(
"SearchEntry",
["key", "value", "event_id", "room_id", "stream_ordering", "origin_server_ts"],
)

@attr.s(slots=True, frozen=True, auto_attribs=True)
class SearchEntry:
key: str
value: str
event_id: str
room_id: str
stream_ordering: Optional[int]
origin_server_ts: int


def _clean_value_for_search(value: str) -> str:
Expand Down