Start fixing places that use the data store.

This commit is contained in:
Erik Johnston 2014-08-14 17:34:37 +01:00
parent 78b501eba6
commit 661c711765
6 changed files with 33 additions and 39 deletions

View File

@ -141,12 +141,7 @@ class MessageHandler(BaseHandler):
yield self.state_handler.handle_new_event(event) yield self.state_handler.handle_new_event(event)
# store in db # store in db
store_id = yield self.store.store_room_data( store_id = yield self.store.persist_event(event)
room_id=event.room_id,
etype=event.type,
state_key=event.state_key,
content=json.dumps(event.content)
)
event.destinations = yield self.store.get_joined_hosts_for_room( event.destinations = yield self.store.get_joined_hosts_for_room(
event.room_id event.room_id
@ -201,19 +196,15 @@ class MessageHandler(BaseHandler):
raise RoomError( raise RoomError(
403, "Member does not meet private room rules.") 403, "Member does not meet private room rules.")
data = yield self.store.get_room_data(room_id, event_type, state_key) data = yield self.store.get_current_state(room_id, event_type, state_key)
defer.returnValue(data) defer.returnValue(data)
@defer.inlineCallbacks @defer.inlineCallbacks
def get_feedback(self, room_id=None, msg_sender_id=None, msg_id=None, def get_feedback(self, event_id):
user_id=None, fb_sender_id=None, fb_type=None):
yield self.auth.check_joined_room(room_id, user_id) yield self.auth.check_joined_room(room_id, user_id)
# Pull out the feedback from the db # Pull out the feedback from the db
fb = yield self.store.get_feedback( fb = yield self.store.get_feedback(event_id)
room_id=room_id, msg_id=msg_id, msg_sender_id=msg_sender_id,
fb_sender_id=fb_sender_id, fb_type=fb_type
)
if fb: if fb:
defer.returnValue(fb) defer.returnValue(fb)

View File

@ -285,25 +285,28 @@ class FeedbackRestServlet(RestServlet):
feedback_type): feedback_type):
user = yield (self.auth.get_user_by_req(request)) user = yield (self.auth.get_user_by_req(request))
if feedback_type not in Feedback.LIST: # TODO (erikj): Implement this?
raise SynapseError(400, "Bad feedback type.", raise NotImplementedError("Getting feedback is not supported")
errcode=Codes.BAD_JSON)
msg_handler = self.handlers.message_handler # if feedback_type not in Feedback.LIST:
feedback = yield msg_handler.get_feedback( # raise SynapseError(400, "Bad feedback type.",
room_id=urllib.unquote(room_id), # errcode=Codes.BAD_JSON)
msg_sender_id=msg_sender_id, #
msg_id=msg_id, # msg_handler = self.handlers.message_handler
user_id=user.to_string(), # feedback = yield msg_handler.get_feedback(
fb_sender_id=fb_sender_id, # room_id=urllib.unquote(room_id),
fb_type=feedback_type # msg_sender_id=msg_sender_id,
) # msg_id=msg_id,
# user_id=user.to_string(),
if not feedback: # fb_sender_id=fb_sender_id,
raise SynapseError(404, "Feedback not found.", # fb_type=feedback_type
errcode=Codes.NOT_FOUND) # )
#
defer.returnValue((200, json.loads(feedback.content))) # if not feedback:
# raise SynapseError(404, "Feedback not found.",
# errcode=Codes.NOT_FOUND)
#
# defer.returnValue((200, json.loads(feedback.content)))
@defer.inlineCallbacks @defer.inlineCallbacks
def on_PUT(self, request, room_id, sender_id, msg_id, fb_sender_id, def on_PUT(self, request, room_id, sender_id, msg_id, fb_sender_id,

View File

@ -21,13 +21,11 @@ from synapse.api.events.room import (
from .directory import DirectoryStore from .directory import DirectoryStore
from .feedback import FeedbackStore from .feedback import FeedbackStore
from .message import MessageStore
from .presence import PresenceStore from .presence import PresenceStore
from .profile import ProfileStore from .profile import ProfileStore
from .registration import RegistrationStore from .registration import RegistrationStore
from .room import RoomStore from .room import RoomStore
from .roommember import RoomMemberStore from .roommember import RoomMemberStore
from .roomdata import RoomDataStore
from .stream import StreamStore from .stream import StreamStore
from .pdu import StatePduStore, PduStore from .pdu import StatePduStore, PduStore
from .transactions import TransactionStore from .transactions import TransactionStore
@ -36,7 +34,7 @@ import json
import os import os
class DataStore(RoomDataStore, RoomMemberStore, MessageStore, RoomStore, class DataStore(RoomMemberStore, RoomStore,
RegistrationStore, StreamStore, ProfileStore, FeedbackStore, RegistrationStore, StreamStore, ProfileStore, FeedbackStore,
PresenceStore, PduStore, StatePduStore, TransactionStore, PresenceStore, PduStore, StatePduStore, TransactionStore,
DirectoryStore): DirectoryStore):
@ -78,7 +76,7 @@ class DataStore(RoomDataStore, RoomMemberStore, MessageStore, RoomStore,
def _store_event(self, event): def _store_event(self, event):
vals = { vals = {
"event_id": event.event_id, "event_id": event.event_id,
"event_type", event.type, "event_type": event.type,
"sender": event.user_id, "sender": event.user_id,
"room_id": event.room_id, "room_id": event.room_id,
"content": json.dumps(event.content), "content": json.dumps(event.content),
@ -105,7 +103,7 @@ class DataStore(RoomDataStore, RoomMemberStore, MessageStore, RoomStore,
# TODO (erikj): We also need to update the current state table? # TODO (erikj): We also need to update the current state table?
@defer.inlineCallbacks @defer.inlineCallbacks
def get_current_state(room_id, event_type=None, state_key="") def get_current_state(room_id, event_type=None, state_key=""):
sql = ( sql = (
"SELECT e.* FROM events as e" "SELECT e.* FROM events as e"
"INNER JOIN current_state as c ON e.event_id = c.event_id " "INNER JOIN current_state as c ON e.event_id = c.event_id "

View File

@ -293,7 +293,7 @@ class SQLBaseStore(object):
def _parse_event_from_row(self, row_dict): def _parse_event_from_row(self, row_dict):
d = copy.deepcopy({k: v for k, v in row.items() if v}) d = copy.deepcopy({k: v for k, v in row.items() if v})
d.update(json.loads(json.loads(row["unrecognized_keys"]))) d.update(json.loads(json.loads(row["unrecognized_keys"])))
d["content"] = json.loads(d["content"}) d["content"] = json.loads(d["content"])
del d["unrecognized_keys"] del d["unrecognized_keys"]
return self.event_factory.create_event( return self.event_factory.create_event(

View File

@ -13,6 +13,8 @@
# 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 twisted.internet import defer
from ._base import SQLBaseStore, Table from ._base import SQLBaseStore, Table
from synapse.api.events.room import FeedbackEvent from synapse.api.events.room import FeedbackEvent
@ -31,7 +33,7 @@ class FeedbackStore(SQLBaseStore):
"sender": event.user_id, "sender": event.user_id,
}) })
@defer.inlineCallback @defer.inlineCallbacks
def get_feedback_for_event(self, event_id): def get_feedback_for_event(self, event_id):
sql = ( sql = (
"SELECT events.* FROM events INNER JOIN feedback " "SELECT events.* FROM events INNER JOIN feedback "

View File

@ -112,7 +112,7 @@ class RoomMemberStore(SQLBaseStore):
args = [user_id] args = [user_id]
args.extend(membership_list) args.extend(membership_list)
where_clause "user_id = ? AND (%s)" % ( where_clause = "user_id = ? AND (%s)" % (
" OR ".join(["membership = ?" for _ in membership_list]), " OR ".join(["membership = ?" for _ in membership_list]),
) )