forked from MirrorHub/synapse
Merge pull request #2828 from matrix-org/rav/kill_memory_datastore
Remove unused/bitrotted MemoryDataStore
This commit is contained in:
commit
d8f90c4208
1 changed files with 13 additions and 151 deletions
164
tests/utils.py
164
tests/utils.py
|
@ -13,27 +13,23 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from synapse.http.server import HttpServer
|
|
||||||
from synapse.api.errors import cs_error, CodeMessageException, StoreError
|
|
||||||
from synapse.api.constants import EventTypes
|
|
||||||
from synapse.storage.prepare_database import prepare_database
|
|
||||||
from synapse.storage.engines import create_engine
|
|
||||||
from synapse.server import HomeServer
|
|
||||||
from synapse.federation.transport import server
|
|
||||||
from synapse.util.ratelimitutils import FederationRateLimiter
|
|
||||||
|
|
||||||
from synapse.util.logcontext import LoggingContext
|
|
||||||
|
|
||||||
from twisted.internet import defer, reactor
|
|
||||||
from twisted.enterprise.adbapi import ConnectionPool
|
|
||||||
|
|
||||||
from collections import namedtuple
|
|
||||||
from mock import patch, Mock
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
from inspect import getcallargs
|
||||||
import urllib
|
import urllib
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
from inspect import getcallargs
|
from mock import Mock, patch
|
||||||
|
from twisted.enterprise.adbapi import ConnectionPool
|
||||||
|
from twisted.internet import defer, reactor
|
||||||
|
|
||||||
|
from synapse.api.errors import CodeMessageException, cs_error
|
||||||
|
from synapse.federation.transport import server
|
||||||
|
from synapse.http.server import HttpServer
|
||||||
|
from synapse.server import HomeServer
|
||||||
|
from synapse.storage.engines import create_engine
|
||||||
|
from synapse.storage.prepare_database import prepare_database
|
||||||
|
from synapse.util.logcontext import LoggingContext
|
||||||
|
from synapse.util.ratelimitutils import FederationRateLimiter
|
||||||
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -334,140 +330,6 @@ class SQLiteMemoryDbPool(ConnectionPool, object):
|
||||||
return create_engine(self.config.database_config)
|
return create_engine(self.config.database_config)
|
||||||
|
|
||||||
|
|
||||||
class MemoryDataStore(object):
|
|
||||||
|
|
||||||
Room = namedtuple(
|
|
||||||
"Room",
|
|
||||||
["room_id", "is_public", "creator"]
|
|
||||||
)
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.tokens_to_users = {}
|
|
||||||
self.paths_to_content = {}
|
|
||||||
|
|
||||||
self.members = {}
|
|
||||||
self.rooms = {}
|
|
||||||
|
|
||||||
self.current_state = {}
|
|
||||||
self.events = []
|
|
||||||
|
|
||||||
class Snapshot(namedtuple("Snapshot", "room_id user_id membership_state")):
|
|
||||||
def fill_out_prev_events(self, event):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def snapshot_room(self, room_id, user_id, state_type=None, state_key=None):
|
|
||||||
return self.Snapshot(
|
|
||||||
room_id, user_id, self.get_room_member(user_id, room_id)
|
|
||||||
)
|
|
||||||
|
|
||||||
def register(self, user_id, token, password_hash):
|
|
||||||
if user_id in self.tokens_to_users.values():
|
|
||||||
raise StoreError(400, "User in use.")
|
|
||||||
self.tokens_to_users[token] = user_id
|
|
||||||
|
|
||||||
def get_user_by_access_token(self, token):
|
|
||||||
try:
|
|
||||||
return {
|
|
||||||
"name": self.tokens_to_users[token],
|
|
||||||
}
|
|
||||||
except Exception:
|
|
||||||
raise StoreError(400, "User does not exist.")
|
|
||||||
|
|
||||||
def get_room(self, room_id):
|
|
||||||
try:
|
|
||||||
return self.rooms[room_id]
|
|
||||||
except Exception:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def store_room(self, room_id, room_creator_user_id, is_public):
|
|
||||||
if room_id in self.rooms:
|
|
||||||
raise StoreError(409, "Conflicting room!")
|
|
||||||
|
|
||||||
room = MemoryDataStore.Room(
|
|
||||||
room_id=room_id,
|
|
||||||
is_public=is_public,
|
|
||||||
creator=room_creator_user_id
|
|
||||||
)
|
|
||||||
self.rooms[room_id] = room
|
|
||||||
|
|
||||||
def get_room_member(self, user_id, room_id):
|
|
||||||
return self.members.get(room_id, {}).get(user_id)
|
|
||||||
|
|
||||||
def get_room_members(self, room_id, membership=None):
|
|
||||||
if membership:
|
|
||||||
return [
|
|
||||||
v for k, v in self.members.get(room_id, {}).items()
|
|
||||||
if v.membership == membership
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
return self.members.get(room_id, {}).values()
|
|
||||||
|
|
||||||
def get_rooms_for_user_where_membership_is(self, user_id, membership_list):
|
|
||||||
return [
|
|
||||||
m[user_id] for m in self.members.values()
|
|
||||||
if user_id in m and m[user_id].membership in membership_list
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_room_events_stream(self, user_id=None, from_key=None, to_key=None,
|
|
||||||
limit=0, with_feedback=False):
|
|
||||||
return ([], from_key) # TODO
|
|
||||||
|
|
||||||
def get_joined_hosts_for_room(self, room_id):
|
|
||||||
return defer.succeed([])
|
|
||||||
|
|
||||||
def persist_event(self, event):
|
|
||||||
if event.type == EventTypes.Member:
|
|
||||||
room_id = event.room_id
|
|
||||||
user = event.state_key
|
|
||||||
self.members.setdefault(room_id, {})[user] = event
|
|
||||||
|
|
||||||
if hasattr(event, "state_key"):
|
|
||||||
key = (event.room_id, event.type, event.state_key)
|
|
||||||
self.current_state[key] = event
|
|
||||||
|
|
||||||
self.events.append(event)
|
|
||||||
|
|
||||||
def get_current_state(self, room_id, event_type=None, state_key=""):
|
|
||||||
if event_type:
|
|
||||||
key = (room_id, event_type, state_key)
|
|
||||||
if self.current_state.get(key):
|
|
||||||
return [self.current_state.get(key)]
|
|
||||||
return None
|
|
||||||
else:
|
|
||||||
return [
|
|
||||||
e for e in self.current_state
|
|
||||||
if e[0] == room_id
|
|
||||||
]
|
|
||||||
|
|
||||||
def set_presence_state(self, user_localpart, state):
|
|
||||||
return defer.succeed({"state": 0})
|
|
||||||
|
|
||||||
def get_presence_list(self, user_localpart, accepted):
|
|
||||||
return []
|
|
||||||
|
|
||||||
def get_room_events_max_id(self):
|
|
||||||
return "s0" # TODO (erikj)
|
|
||||||
|
|
||||||
def get_send_event_level(self, room_id):
|
|
||||||
return defer.succeed(0)
|
|
||||||
|
|
||||||
def get_power_level(self, room_id, user_id):
|
|
||||||
return defer.succeed(0)
|
|
||||||
|
|
||||||
def get_add_state_level(self, room_id):
|
|
||||||
return defer.succeed(0)
|
|
||||||
|
|
||||||
def get_room_join_rule(self, room_id):
|
|
||||||
# TODO (erikj): This should be configurable
|
|
||||||
return defer.succeed("invite")
|
|
||||||
|
|
||||||
def get_ops_levels(self, room_id):
|
|
||||||
return defer.succeed((5, 5, 5))
|
|
||||||
|
|
||||||
def insert_client_ip(self, user, access_token, ip, user_agent):
|
|
||||||
return defer.succeed(None)
|
|
||||||
|
|
||||||
|
|
||||||
def _format_call(args, kwargs):
|
def _format_call(args, kwargs):
|
||||||
return ", ".join(
|
return ", ".join(
|
||||||
["%r" % (a) for a in args] +
|
["%r" % (a) for a in args] +
|
||||||
|
|
Loading…
Reference in a new issue