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

Commit

Permalink
Don't call SQLBaseStore methods from outside stores
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Dec 4, 2019
1 parent 3eb15c0 commit c2f525a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,8 @@ def phone_stats_home(hs, stats, stats_process=_stats_process):
# Database version
#

stats["database_engine"] = hs.get_datastore().database_engine_name
stats["database_server_version"] = hs.get_datastore().get_server_version()
stats["database_engine"] = hs.database_engine.module.__name__
stats["database_server_version"] = hs.database_engine.server_version
logger.info("Reporting stats to %s: %s" % (hs.config.report_stats_endpoint, stats))
try:
yield hs.get_proxied_http_client().put_json(
Expand Down
10 changes: 1 addition & 9 deletions synapse/push/bulk_push_rule_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,7 @@ def _update_rules_with_member_event_ids(
"""
sequence = self.sequence

rows = yield self.store._simple_select_many_batch(
table="room_memberships",
column="event_id",
iterable=member_event_ids.values(),
retcols=("user_id", "membership", "event_id"),
keyvalues={},
batch_size=500,
desc="_get_rules_for_member_event_ids",
)
rows = yield self.store.get_membership_from_event_ids(member_event_ids.values())

members = {row["event_id"]: (row["user_id"], row["membership"]) for row in rows}

Expand Down
8 changes: 0 additions & 8 deletions synapse/storage/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1496,14 +1496,6 @@ def _simple_search_list_txn(cls, txn, table, term, col, retcols):

return cls.cursor_to_dict(txn)

@property
def database_engine_name(self):
return self.database_engine.module.__name__

def get_server_version(self):
"""Returns a string describing the server version number"""
return self.database_engine.server_version


class _RollbackButIsFineException(Exception):
""" This exception is used to rollback a transaction without implying
Expand Down
17 changes: 17 additions & 0 deletions synapse/storage/data_stores/main/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

import logging
from typing import Iterable, List

from six import iteritems, itervalues

Expand Down Expand Up @@ -813,6 +814,22 @@ def get_rooms_user_has_been_in(self, user_id):

return set(room_ids)

def get_membership_from_event_ids(
self, member_event_ids: Iterable[str]
) -> List[dict]:
"""Get user_id and membership of a set of event IDs.
"""

return self._simple_select_many_batch(
table="room_memberships",
column="event_id",
iterable=member_event_ids,
retcols=("user_id", "membership", "event_id"),
keyvalues={},
batch_size=500,
desc="get_membership_from_event_ids",
)


class RoomMemberBackgroundUpdateStore(BackgroundUpdateStore):
def __init__(self, db_conn, hs):
Expand Down

0 comments on commit c2f525a

Please sign in to comment.