Persist internal_metadata

This commit is contained in:
Erik Johnston 2014-12-16 13:17:09 +00:00
parent 4afac88390
commit 882dc8dcab
4 changed files with 13 additions and 5 deletions

View File

@ -111,7 +111,7 @@ class EventBase(object):
class FrozenEvent(EventBase): class FrozenEvent(EventBase):
def __init__(self, event_dict): def __init__(self, event_dict, internal_metadata_dict={}):
event_dict = copy.deepcopy(event_dict) event_dict = copy.deepcopy(event_dict)
signatures = copy.deepcopy(event_dict.pop("signatures", {})) signatures = copy.deepcopy(event_dict.pop("signatures", {}))
@ -122,7 +122,8 @@ class FrozenEvent(EventBase):
super(FrozenEvent, self).__init__( super(FrozenEvent, self).__init__(
frozen_dict, frozen_dict,
signatures=signatures, signatures=signatures,
unsigned=unsigned unsigned=unsigned,
internal_metadata_dict=internal_metadata_dict,
) )
@staticmethod @staticmethod

View File

@ -156,12 +156,17 @@ class DataStore(RoomMemberStore, RoomStore,
] ]
} }
metadata_json = encode_canonical_json(
event.internal_metadata.get_dict()
)
self._simple_insert_txn( self._simple_insert_txn(
txn, txn,
table="event_json", table="event_json",
values={ values={
"event_id": event.event_id, "event_id": event.event_id,
"room_id": event.room_id, "room_id": event.room_id,
"internal_metadata": metadata_json.decode("UTF-8"),
"json": encode_canonical_json(event_dict).decode("UTF-8"), "json": encode_canonical_json(event_dict).decode("UTF-8"),
}, },
or_replace=True, or_replace=True,

View File

@ -452,7 +452,7 @@ class SQLBaseStore(object):
def _get_event_txn(self, txn, event_id, check_redacted=True, def _get_event_txn(self, txn, event_id, check_redacted=True,
get_prev_content=True): get_prev_content=True):
sql = ( sql = (
"SELECT json, r.event_id FROM event_json as e " "SELECT internal_metadata, json, r.event_id FROM event_json as e "
"LEFT JOIN redactions as r ON e.event_id = r.redacts " "LEFT JOIN redactions as r ON e.event_id = r.redacts "
"WHERE e.event_id = ? " "WHERE e.event_id = ? "
"LIMIT 1 " "LIMIT 1 "
@ -465,11 +465,12 @@ class SQLBaseStore(object):
if not res: if not res:
return None return None
js, redacted = res internal_metadata, js, redacted = res
d = json.loads(js) d = json.loads(js)
internal_metadata = json.loads(internal_metadata)
ev = FrozenEvent(d) ev = FrozenEvent(d, internal_metadata_dict=internal_metadata)
if check_redacted and redacted: if check_redacted and redacted:
ev = prune_event(ev) ev = prune_event(ev)

View File

@ -36,6 +36,7 @@ CREATE INDEX IF NOT EXISTS events_room_id ON events (room_id);
CREATE TABLE IF NOT EXISTS event_json( CREATE TABLE IF NOT EXISTS event_json(
event_id TEXT NOT NULL, event_id TEXT NOT NULL,
room_id TEXT NOT NULL, room_id TEXT NOT NULL,
internal_metadata NOT NULL,
json BLOB NOT NULL, json BLOB NOT NULL,
CONSTRAINT ev_j_uniq UNIQUE (event_id) CONSTRAINT ev_j_uniq UNIQUE (event_id)
); );