mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-12-25 13:19:22 -05:00
Merge pull request #482 from matrix-org/markjh/table_name
Finish removing the .*Table objects from the storage layer.
This commit is contained in:
commit
37716d55ed
@ -42,7 +42,7 @@ class EventPushActionsStore(SQLBaseStore):
|
||||
yield self.runInteraction(
|
||||
"set_actions_for_event_and_users",
|
||||
self._simple_insert_many_txn,
|
||||
EventPushActionsTable.table_name,
|
||||
"event_push_actions",
|
||||
values
|
||||
)
|
||||
|
||||
@ -104,7 +104,3 @@ class EventPushActionsStore(SQLBaseStore):
|
||||
"remove_push_actions_for_event_id",
|
||||
f
|
||||
)
|
||||
|
||||
|
||||
class EventPushActionsTable(object):
|
||||
table_name = "event_push_actions"
|
||||
|
@ -27,11 +27,14 @@ class PushRuleStore(SQLBaseStore):
|
||||
@cachedInlineCallbacks()
|
||||
def get_push_rules_for_user(self, user_name):
|
||||
rows = yield self._simple_select_list(
|
||||
table=PushRuleTable.table_name,
|
||||
table="push_rules",
|
||||
keyvalues={
|
||||
"user_name": user_name,
|
||||
},
|
||||
retcols=PushRuleTable.fields,
|
||||
retcols=(
|
||||
"user_name", "rule_id", "priority_class", "priority",
|
||||
"conditions", "actions",
|
||||
),
|
||||
desc="get_push_rules_enabled_for_user",
|
||||
)
|
||||
|
||||
@ -44,11 +47,13 @@ class PushRuleStore(SQLBaseStore):
|
||||
@cachedInlineCallbacks()
|
||||
def get_push_rules_enabled_for_user(self, user_name):
|
||||
results = yield self._simple_select_list(
|
||||
table=PushRuleEnableTable.table_name,
|
||||
table="push_rules_enable",
|
||||
keyvalues={
|
||||
'user_name': user_name
|
||||
},
|
||||
retcols=PushRuleEnableTable.fields,
|
||||
retcols=(
|
||||
"user_name", "rule_id", "enabled",
|
||||
),
|
||||
desc="get_push_rules_enabled_for_user",
|
||||
)
|
||||
defer.returnValue({
|
||||
@ -65,12 +70,12 @@ class PushRuleStore(SQLBaseStore):
|
||||
def f(txn, user_ids_to_fetch):
|
||||
sql = (
|
||||
"SELECT pr.*"
|
||||
" FROM push_rules as pr "
|
||||
" LEFT JOIN push_rules_enable as pre "
|
||||
" ON pr.user_name = pre.user_name and pr.rule_id = pre.rule_id "
|
||||
" WHERE pr.user_name "
|
||||
" FROM push_rules AS pr"
|
||||
" LEFT JOIN push_rules_enable AS pre"
|
||||
" ON pr.user_name = pre.user_name AND pr.rule_id = pre.rule_id"
|
||||
" WHERE pr.user_name"
|
||||
" 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"
|
||||
)
|
||||
txn.execute(sql, user_ids_to_fetch)
|
||||
@ -123,7 +128,7 @@ class PushRuleStore(SQLBaseStore):
|
||||
|
||||
res = self._simple_select_one_txn(
|
||||
txn,
|
||||
table=PushRuleTable.table_name,
|
||||
table="push_rules",
|
||||
keyvalues={
|
||||
"user_name": user_name,
|
||||
"rule_id": relative_to_rule,
|
||||
@ -162,7 +167,7 @@ class PushRuleStore(SQLBaseStore):
|
||||
new_rule['priority'] = new_rule_priority
|
||||
|
||||
sql = (
|
||||
"SELECT COUNT(*) FROM " + PushRuleTable.table_name +
|
||||
"SELECT COUNT(*) FROM push_rules"
|
||||
" WHERE user_name = ? AND priority_class = ? AND 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 num_conflicting:
|
||||
sql = "UPDATE "+PushRuleTable.table_name+" SET priority = priority "
|
||||
sql = "UPDATE push_rules SET priority = priority "
|
||||
if after:
|
||||
sql += "-1"
|
||||
else:
|
||||
@ -194,7 +199,7 @@ class PushRuleStore(SQLBaseStore):
|
||||
|
||||
self._simple_insert_txn(
|
||||
txn,
|
||||
table=PushRuleTable.table_name,
|
||||
table="push_rules",
|
||||
values=new_rule,
|
||||
)
|
||||
|
||||
@ -202,7 +207,7 @@ class PushRuleStore(SQLBaseStore):
|
||||
priority_class, **kwargs):
|
||||
# find the highest priority rule in that class
|
||||
sql = (
|
||||
"SELECT COUNT(*), MAX(priority) FROM " + PushRuleTable.table_name +
|
||||
"SELECT COUNT(*), MAX(priority) FROM push_rules"
|
||||
" WHERE user_name = ? and priority_class = ?"
|
||||
)
|
||||
txn.execute(sql, (user_name, priority_class))
|
||||
@ -229,7 +234,7 @@ class PushRuleStore(SQLBaseStore):
|
||||
|
||||
self._simple_insert_txn(
|
||||
txn,
|
||||
table=PushRuleTable.table_name,
|
||||
table="push_rules",
|
||||
values=new_rule,
|
||||
)
|
||||
|
||||
@ -245,7 +250,7 @@ class PushRuleStore(SQLBaseStore):
|
||||
rule_id (str): The rule_id of the rule to be deleted
|
||||
"""
|
||||
yield self._simple_delete_one(
|
||||
PushRuleTable.table_name,
|
||||
"push_rules",
|
||||
{'user_name': user_name, 'rule_id': rule_id},
|
||||
desc="delete_push_rule",
|
||||
)
|
||||
@ -266,7 +271,7 @@ class PushRuleStore(SQLBaseStore):
|
||||
new_id = self._push_rules_enable_id_gen.get_next_txn(txn)
|
||||
self._simple_upsert_txn(
|
||||
txn,
|
||||
PushRuleEnableTable.table_name,
|
||||
"push_rules_enable",
|
||||
{'user_name': user_name, 'rule_id': rule_id},
|
||||
{'enabled': 1 if enabled else 0},
|
||||
{'id': new_id},
|
||||
@ -285,27 +290,3 @@ class RuleNotFoundException(Exception):
|
||||
|
||||
class InconsistentRuleException(Exception):
|
||||
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"
|
||||
]
|
||||
|
@ -86,7 +86,7 @@ class PusherStore(SQLBaseStore):
|
||||
try:
|
||||
next_id = yield self._pushers_id_gen.get_next()
|
||||
yield self._simple_upsert(
|
||||
PushersTable.table_name,
|
||||
"pushers",
|
||||
dict(
|
||||
app_id=app_id,
|
||||
pushkey=pushkey,
|
||||
@ -114,7 +114,7 @@ class PusherStore(SQLBaseStore):
|
||||
@defer.inlineCallbacks
|
||||
def delete_pusher_by_app_id_pushkey_user_name(self, app_id, pushkey, user_name):
|
||||
yield self._simple_delete_one(
|
||||
PushersTable.table_name,
|
||||
"pushers",
|
||||
{"app_id": app_id, "pushkey": pushkey, 'user_name': user_name},
|
||||
desc="delete_pusher_by_app_id_pushkey_user_name",
|
||||
)
|
||||
@ -122,7 +122,7 @@ class PusherStore(SQLBaseStore):
|
||||
@defer.inlineCallbacks
|
||||
def update_pusher_last_token(self, app_id, pushkey, user_name, last_token):
|
||||
yield self._simple_update_one(
|
||||
PushersTable.table_name,
|
||||
"pushers",
|
||||
{'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name},
|
||||
{'last_token': 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,
|
||||
last_token, last_success):
|
||||
yield self._simple_update_one(
|
||||
PushersTable.table_name,
|
||||
"pushers",
|
||||
{'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name},
|
||||
{'last_token': last_token, 'last_success': last_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,
|
||||
failing_since):
|
||||
yield self._simple_update_one(
|
||||
PushersTable.table_name,
|
||||
"pushers",
|
||||
{'app_id': app_id, 'pushkey': pushkey, 'user_name': user_name},
|
||||
{'failing_since': failing_since},
|
||||
desc="update_pusher_failing_since",
|
||||
)
|
||||
|
||||
|
||||
class PushersTable(object):
|
||||
table_name = "pushers"
|
||||
|
@ -49,7 +49,7 @@ class RoomStore(SQLBaseStore):
|
||||
"""
|
||||
try:
|
||||
yield self._simple_insert(
|
||||
RoomsTable.table_name,
|
||||
"rooms",
|
||||
{
|
||||
"room_id": room_id,
|
||||
"creator": room_creator_user_id,
|
||||
@ -70,9 +70,9 @@ class RoomStore(SQLBaseStore):
|
||||
A namedtuple containing the room information, or an empty list.
|
||||
"""
|
||||
return self._simple_select_one(
|
||||
table=RoomsTable.table_name,
|
||||
table="rooms",
|
||||
keyvalues={"room_id": room_id},
|
||||
retcols=RoomsTable.fields,
|
||||
retcols=("room_id", "is_public", "creator"),
|
||||
desc="get_room",
|
||||
allow_none=True,
|
||||
)
|
||||
@ -275,13 +275,3 @@ class RoomStore(SQLBaseStore):
|
||||
aliases.extend(e.content['aliases'])
|
||||
|
||||
defer.returnValue((name, aliases))
|
||||
|
||||
|
||||
class RoomsTable(object):
|
||||
table_name = "rooms"
|
||||
|
||||
fields = [
|
||||
"room_id",
|
||||
"is_public",
|
||||
"creator"
|
||||
]
|
||||
|
@ -16,8 +16,6 @@
|
||||
from ._base import SQLBaseStore
|
||||
from synapse.util.caches.descriptors import cached
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
from canonicaljson import encode_canonical_json
|
||||
import logging
|
||||
|
||||
@ -50,12 +48,15 @@ class TransactionStore(SQLBaseStore):
|
||||
def _get_received_txn_response(self, txn, transaction_id, origin):
|
||||
result = self._simple_select_one_txn(
|
||||
txn,
|
||||
table=ReceivedTransactionsTable.table_name,
|
||||
table="received_transactions",
|
||||
keyvalues={
|
||||
"transaction_id": transaction_id,
|
||||
"origin": origin,
|
||||
},
|
||||
retcols=ReceivedTransactionsTable.fields,
|
||||
retcols=(
|
||||
"transaction_id", "origin", "ts", "response_code", "response_json",
|
||||
"has_been_referenced",
|
||||
),
|
||||
allow_none=True,
|
||||
)
|
||||
|
||||
@ -79,7 +80,7 @@ class TransactionStore(SQLBaseStore):
|
||||
"""
|
||||
|
||||
return self._simple_insert(
|
||||
table=ReceivedTransactionsTable.table_name,
|
||||
table="received_transactions",
|
||||
values={
|
||||
"transaction_id": transaction_id,
|
||||
"origin": origin,
|
||||
@ -136,7 +137,7 @@ class TransactionStore(SQLBaseStore):
|
||||
|
||||
self._simple_insert_txn(
|
||||
txn,
|
||||
table=SentTransactions.table_name,
|
||||
table="sent_transactions",
|
||||
values={
|
||||
"id": next_id,
|
||||
"transaction_id": transaction_id,
|
||||
@ -171,7 +172,7 @@ class TransactionStore(SQLBaseStore):
|
||||
code, response_json):
|
||||
self._simple_update_one_txn(
|
||||
txn,
|
||||
table=SentTransactions.table_name,
|
||||
table="sent_transactions",
|
||||
keyvalues={
|
||||
"transaction_id": transaction_id,
|
||||
"destination": destination,
|
||||
@ -229,11 +230,11 @@ class TransactionStore(SQLBaseStore):
|
||||
def _get_destination_retry_timings(self, txn, destination):
|
||||
result = self._simple_select_one_txn(
|
||||
txn,
|
||||
table=DestinationsTable.table_name,
|
||||
table="destinations",
|
||||
keyvalues={
|
||||
"destination": destination,
|
||||
},
|
||||
retcols=DestinationsTable.fields,
|
||||
retcols=("destination", "retry_last_ts", "retry_interval"),
|
||||
allow_none=True,
|
||||
)
|
||||
|
||||
@ -304,52 +305,3 @@ class TransactionStore(SQLBaseStore):
|
||||
|
||||
txn.execute(query, (self._clock.time_msec(),))
|
||||
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",
|
||||
]
|
||||
|
@ -28,7 +28,6 @@ from synapse.api.constants import PresenceState
|
||||
from synapse.api.errors import SynapseError
|
||||
from synapse.handlers.presence import PresenceHandler, UserPresenceCache
|
||||
from synapse.streams.config import SourcePaginationConfig
|
||||
from synapse.storage.transactions import DestinationsTable
|
||||
from synapse.types import UserID
|
||||
|
||||
OFFLINE = PresenceState.OFFLINE
|
||||
|
@ -27,7 +27,6 @@ from ..utils import (
|
||||
from synapse.api.errors import AuthError
|
||||
from synapse.handlers.typing import TypingNotificationHandler
|
||||
|
||||
from synapse.storage.transactions import DestinationsTable
|
||||
from synapse.types import UserID
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user