Merge pull request #482 from matrix-org/markjh/table_name

Finish removing the .*Table objects from the storage layer.
This commit is contained in:
Mark Haines 2016-01-13 13:45:39 +01:00
commit 37716d55ed
7 changed files with 41 additions and 128 deletions

View File

@ -42,7 +42,7 @@ class EventPushActionsStore(SQLBaseStore):
yield self.runInteraction( yield self.runInteraction(
"set_actions_for_event_and_users", "set_actions_for_event_and_users",
self._simple_insert_many_txn, self._simple_insert_many_txn,
EventPushActionsTable.table_name, "event_push_actions",
values values
) )
@ -104,7 +104,3 @@ class EventPushActionsStore(SQLBaseStore):
"remove_push_actions_for_event_id", "remove_push_actions_for_event_id",
f f
) )
class EventPushActionsTable(object):
table_name = "event_push_actions"

View File

@ -27,11 +27,14 @@ class PushRuleStore(SQLBaseStore):
@cachedInlineCallbacks() @cachedInlineCallbacks()
def get_push_rules_for_user(self, user_name): def get_push_rules_for_user(self, user_name):
rows = yield self._simple_select_list( rows = yield self._simple_select_list(
table=PushRuleTable.table_name, table="push_rules",
keyvalues={ keyvalues={
"user_name": user_name, "user_name": user_name,
}, },
retcols=PushRuleTable.fields, retcols=(
"user_name", "rule_id", "priority_class", "priority",
"conditions", "actions",
),
desc="get_push_rules_enabled_for_user", desc="get_push_rules_enabled_for_user",
) )
@ -44,11 +47,13 @@ class PushRuleStore(SQLBaseStore):
@cachedInlineCallbacks() @cachedInlineCallbacks()
def get_push_rules_enabled_for_user(self, user_name): def get_push_rules_enabled_for_user(self, user_name):
results = yield self._simple_select_list( results = yield self._simple_select_list(
table=PushRuleEnableTable.table_name, table="push_rules_enable",
keyvalues={ keyvalues={
'user_name': user_name 'user_name': user_name
}, },
retcols=PushRuleEnableTable.fields, retcols=(
"user_name", "rule_id", "enabled",
),
desc="get_push_rules_enabled_for_user", desc="get_push_rules_enabled_for_user",
) )
defer.returnValue({ defer.returnValue({
@ -65,12 +70,12 @@ class PushRuleStore(SQLBaseStore):
def f(txn, user_ids_to_fetch): def f(txn, user_ids_to_fetch):
sql = ( sql = (
"SELECT pr.*" "SELECT pr.*"
" FROM push_rules as pr " " FROM push_rules AS pr"
" LEFT JOIN push_rules_enable as pre " " LEFT JOIN push_rules_enable AS pre"
" ON pr.user_name = pre.user_name and pr.rule_id = pre.rule_id " " ON pr.user_name = pre.user_name AND pr.rule_id = pre.rule_id"
" WHERE pr.user_name " " WHERE pr.user_name"
" IN (" + ",".join("?" for _ in user_ids_to_fetch) + ")" " IN (" + ",".join("?" for _ in user_ids_to_fetch) + ")"
" AND (pre.enabled is null or pre.enabled = 1)" " AND (pre.enabled IS NULL OR pre.enabled = 1)"
" ORDER BY pr.user_name, pr.priority_class DESC, pr.priority DESC" " ORDER BY pr.user_name, pr.priority_class DESC, pr.priority DESC"
) )
txn.execute(sql, user_ids_to_fetch) txn.execute(sql, user_ids_to_fetch)
@ -123,7 +128,7 @@ class PushRuleStore(SQLBaseStore):
res = self._simple_select_one_txn( res = self._simple_select_one_txn(
txn, txn,
table=PushRuleTable.table_name, table="push_rules",
keyvalues={ keyvalues={
"user_name": user_name, "user_name": user_name,
"rule_id": relative_to_rule, "rule_id": relative_to_rule,
@ -162,7 +167,7 @@ class PushRuleStore(SQLBaseStore):
new_rule['priority'] = new_rule_priority new_rule['priority'] = new_rule_priority
sql = ( sql = (
"SELECT COUNT(*) FROM " + PushRuleTable.table_name + "SELECT COUNT(*) FROM push_rules"
" WHERE user_name = ? AND priority_class = ? AND priority = ?" " WHERE user_name = ? AND priority_class = ? AND priority = ?"
) )
txn.execute(sql, (user_name, priority_class, new_rule_priority)) txn.execute(sql, (user_name, priority_class, new_rule_priority))
@ -171,7 +176,7 @@ class PushRuleStore(SQLBaseStore):
# if there are conflicting rules, bump everything # if there are conflicting rules, bump everything
if num_conflicting: if num_conflicting:
sql = "UPDATE "+PushRuleTable.table_name+" SET priority = priority " sql = "UPDATE push_rules SET priority = priority "
if after: if after:
sql += "-1" sql += "-1"
else: else:
@ -194,7 +199,7 @@ class PushRuleStore(SQLBaseStore):
self._simple_insert_txn( self._simple_insert_txn(
txn, txn,
table=PushRuleTable.table_name, table="push_rules",
values=new_rule, values=new_rule,
) )
@ -202,7 +207,7 @@ class PushRuleStore(SQLBaseStore):
priority_class, **kwargs): priority_class, **kwargs):
# find the highest priority rule in that class # find the highest priority rule in that class
sql = ( sql = (
"SELECT COUNT(*), MAX(priority) FROM " + PushRuleTable.table_name + "SELECT COUNT(*), MAX(priority) FROM push_rules"
" WHERE user_name = ? and priority_class = ?" " WHERE user_name = ? and priority_class = ?"
) )
txn.execute(sql, (user_name, priority_class)) txn.execute(sql, (user_name, priority_class))
@ -229,7 +234,7 @@ class PushRuleStore(SQLBaseStore):
self._simple_insert_txn( self._simple_insert_txn(
txn, txn,
table=PushRuleTable.table_name, table="push_rules",
values=new_rule, values=new_rule,
) )
@ -245,7 +250,7 @@ class PushRuleStore(SQLBaseStore):
rule_id (str): The rule_id of the rule to be deleted rule_id (str): The rule_id of the rule to be deleted
""" """
yield self._simple_delete_one( yield self._simple_delete_one(
PushRuleTable.table_name, "push_rules",
{'user_name': user_name, 'rule_id': rule_id}, {'user_name': user_name, 'rule_id': rule_id},
desc="delete_push_rule", desc="delete_push_rule",
) )
@ -266,7 +271,7 @@ class PushRuleStore(SQLBaseStore):
new_id = self._push_rules_enable_id_gen.get_next_txn(txn) new_id = self._push_rules_enable_id_gen.get_next_txn(txn)
self._simple_upsert_txn( self._simple_upsert_txn(
txn, txn,
PushRuleEnableTable.table_name, "push_rules_enable",
{'user_name': user_name, 'rule_id': rule_id}, {'user_name': user_name, 'rule_id': rule_id},
{'enabled': 1 if enabled else 0}, {'enabled': 1 if enabled else 0},
{'id': new_id}, {'id': new_id},
@ -285,27 +290,3 @@ class RuleNotFoundException(Exception):
class InconsistentRuleException(Exception): class InconsistentRuleException(Exception):
pass pass
class PushRuleTable(object):
table_name = "push_rules"
fields = [
"id",
"user_name",
"rule_id",
"priority_class",
"priority",
"conditions",
"actions",
]
class PushRuleEnableTable(object):
table_name = "push_rules_enable"
fields = [
"user_name",
"rule_id",
"enabled"
]

View File

@ -86,7 +86,7 @@ class PusherStore(SQLBaseStore):
try: try:
next_id = yield self._pushers_id_gen.get_next() next_id = yield self._pushers_id_gen.get_next()
yield self._simple_upsert( yield self._simple_upsert(
PushersTable.table_name, "pushers",
dict( dict(
app_id=app_id, app_id=app_id,
pushkey=pushkey, pushkey=pushkey,
@ -114,7 +114,7 @@ class PusherStore(SQLBaseStore):
@defer.inlineCallbacks @defer.inlineCallbacks
def delete_pusher_by_app_id_pushkey_user_name(self, app_id, pushkey, user_name): def delete_pusher_by_app_id_pushkey_user_name(self, app_id, pushkey, user_name):
yield self._simple_delete_one( yield self._simple_delete_one(
PushersTable.table_name, "pushers",
{"app_id": app_id, "pushkey": pushkey, 'user_name': user_name}, {"app_id": app_id, "pushkey": pushkey, 'user_name': user_name},
desc="delete_pusher_by_app_id_pushkey_user_name", desc="delete_pusher_by_app_id_pushkey_user_name",
) )
@ -122,7 +122,7 @@ class PusherStore(SQLBaseStore):
@defer.inlineCallbacks @defer.inlineCallbacks
def update_pusher_last_token(self, app_id, pushkey, user_name, last_token): def update_pusher_last_token(self, app_id, pushkey, user_name, last_token):
yield self._simple_update_one( yield self._simple_update_one(
PushersTable.table_name, "pushers",
{'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name}, {'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name},
{'last_token': last_token}, {'last_token': last_token},
desc="update_pusher_last_token", desc="update_pusher_last_token",
@ -132,7 +132,7 @@ class PusherStore(SQLBaseStore):
def update_pusher_last_token_and_success(self, app_id, pushkey, user_name, def update_pusher_last_token_and_success(self, app_id, pushkey, user_name,
last_token, last_success): last_token, last_success):
yield self._simple_update_one( yield self._simple_update_one(
PushersTable.table_name, "pushers",
{'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name}, {'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name},
{'last_token': last_token, 'last_success': last_success}, {'last_token': last_token, 'last_success': last_success},
desc="update_pusher_last_token_and_success", desc="update_pusher_last_token_and_success",
@ -142,12 +142,8 @@ class PusherStore(SQLBaseStore):
def update_pusher_failing_since(self, app_id, pushkey, user_name, def update_pusher_failing_since(self, app_id, pushkey, user_name,
failing_since): failing_since):
yield self._simple_update_one( yield self._simple_update_one(
PushersTable.table_name, "pushers",
{'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name}, {'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name},
{'failing_since': failing_since}, {'failing_since': failing_since},
desc="update_pusher_failing_since", desc="update_pusher_failing_since",
) )
class PushersTable(object):
table_name = "pushers"

View File

@ -49,7 +49,7 @@ class RoomStore(SQLBaseStore):
""" """
try: try:
yield self._simple_insert( yield self._simple_insert(
RoomsTable.table_name, "rooms",
{ {
"room_id": room_id, "room_id": room_id,
"creator": room_creator_user_id, "creator": room_creator_user_id,
@ -70,9 +70,9 @@ class RoomStore(SQLBaseStore):
A namedtuple containing the room information, or an empty list. A namedtuple containing the room information, or an empty list.
""" """
return self._simple_select_one( return self._simple_select_one(
table=RoomsTable.table_name, table="rooms",
keyvalues={"room_id": room_id}, keyvalues={"room_id": room_id},
retcols=RoomsTable.fields, retcols=("room_id", "is_public", "creator"),
desc="get_room", desc="get_room",
allow_none=True, allow_none=True,
) )
@ -275,13 +275,3 @@ class RoomStore(SQLBaseStore):
aliases.extend(e.content['aliases']) aliases.extend(e.content['aliases'])
defer.returnValue((name, aliases)) defer.returnValue((name, aliases))
class RoomsTable(object):
table_name = "rooms"
fields = [
"room_id",
"is_public",
"creator"
]

View File

@ -16,8 +16,6 @@
from ._base import SQLBaseStore from ._base import SQLBaseStore
from synapse.util.caches.descriptors import cached from synapse.util.caches.descriptors import cached
from collections import namedtuple
from canonicaljson import encode_canonical_json from canonicaljson import encode_canonical_json
import logging import logging
@ -50,12 +48,15 @@ class TransactionStore(SQLBaseStore):
def _get_received_txn_response(self, txn, transaction_id, origin): def _get_received_txn_response(self, txn, transaction_id, origin):
result = self._simple_select_one_txn( result = self._simple_select_one_txn(
txn, txn,
table=ReceivedTransactionsTable.table_name, table="received_transactions",
keyvalues={ keyvalues={
"transaction_id": transaction_id, "transaction_id": transaction_id,
"origin": origin, "origin": origin,
}, },
retcols=ReceivedTransactionsTable.fields, retcols=(
"transaction_id", "origin", "ts", "response_code", "response_json",
"has_been_referenced",
),
allow_none=True, allow_none=True,
) )
@ -79,7 +80,7 @@ class TransactionStore(SQLBaseStore):
""" """
return self._simple_insert( return self._simple_insert(
table=ReceivedTransactionsTable.table_name, table="received_transactions",
values={ values={
"transaction_id": transaction_id, "transaction_id": transaction_id,
"origin": origin, "origin": origin,
@ -136,7 +137,7 @@ class TransactionStore(SQLBaseStore):
self._simple_insert_txn( self._simple_insert_txn(
txn, txn,
table=SentTransactions.table_name, table="sent_transactions",
values={ values={
"id": next_id, "id": next_id,
"transaction_id": transaction_id, "transaction_id": transaction_id,
@ -171,7 +172,7 @@ class TransactionStore(SQLBaseStore):
code, response_json): code, response_json):
self._simple_update_one_txn( self._simple_update_one_txn(
txn, txn,
table=SentTransactions.table_name, table="sent_transactions",
keyvalues={ keyvalues={
"transaction_id": transaction_id, "transaction_id": transaction_id,
"destination": destination, "destination": destination,
@ -229,11 +230,11 @@ class TransactionStore(SQLBaseStore):
def _get_destination_retry_timings(self, txn, destination): def _get_destination_retry_timings(self, txn, destination):
result = self._simple_select_one_txn( result = self._simple_select_one_txn(
txn, txn,
table=DestinationsTable.table_name, table="destinations",
keyvalues={ keyvalues={
"destination": destination, "destination": destination,
}, },
retcols=DestinationsTable.fields, retcols=("destination", "retry_last_ts", "retry_interval"),
allow_none=True, allow_none=True,
) )
@ -304,52 +305,3 @@ class TransactionStore(SQLBaseStore):
txn.execute(query, (self._clock.time_msec(),)) txn.execute(query, (self._clock.time_msec(),))
return self.cursor_to_dict(txn) return self.cursor_to_dict(txn)
class ReceivedTransactionsTable(object):
table_name = "received_transactions"
fields = [
"transaction_id",
"origin",
"ts",
"response_code",
"response_json",
"has_been_referenced",
]
class SentTransactions(object):
table_name = "sent_transactions"
fields = [
"id",
"transaction_id",
"destination",
"ts",
"response_code",
"response_json",
]
EntryType = namedtuple("SentTransactionsEntry", fields)
class TransactionsToPduTable(object):
table_name = "transaction_id_to_pdu"
fields = [
"transaction_id",
"destination",
"pdu_id",
"pdu_origin",
]
class DestinationsTable(object):
table_name = "destinations"
fields = [
"destination",
"retry_last_ts",
"retry_interval",
]

View File

@ -28,7 +28,6 @@ from synapse.api.constants import PresenceState
from synapse.api.errors import SynapseError from synapse.api.errors import SynapseError
from synapse.handlers.presence import PresenceHandler, UserPresenceCache from synapse.handlers.presence import PresenceHandler, UserPresenceCache
from synapse.streams.config import SourcePaginationConfig from synapse.streams.config import SourcePaginationConfig
from synapse.storage.transactions import DestinationsTable
from synapse.types import UserID from synapse.types import UserID
OFFLINE = PresenceState.OFFLINE OFFLINE = PresenceState.OFFLINE

View File

@ -27,7 +27,6 @@ from ..utils import (
from synapse.api.errors import AuthError from synapse.api.errors import AuthError
from synapse.handlers.typing import TypingNotificationHandler from synapse.handlers.typing import TypingNotificationHandler
from synapse.storage.transactions import DestinationsTable
from synapse.types import UserID from synapse.types import UserID