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):
def __init__(self, event_dict):
def __init__(self, event_dict, internal_metadata_dict={}):
event_dict = copy.deepcopy(event_dict)
signatures = copy.deepcopy(event_dict.pop("signatures", {}))
@ -122,7 +122,8 @@ class FrozenEvent(EventBase):
super(FrozenEvent, self).__init__(
frozen_dict,
signatures=signatures,
unsigned=unsigned
unsigned=unsigned,
internal_metadata_dict=internal_metadata_dict,
)
@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(
txn,
table="event_json",
values={
"event_id": event.event_id,
"room_id": event.room_id,
"internal_metadata": metadata_json.decode("UTF-8"),
"json": encode_canonical_json(event_dict).decode("UTF-8"),
},
or_replace=True,

View File

@ -452,7 +452,7 @@ class SQLBaseStore(object):
def _get_event_txn(self, txn, event_id, check_redacted=True,
get_prev_content=True):
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 "
"WHERE e.event_id = ? "
"LIMIT 1 "
@ -465,11 +465,12 @@ class SQLBaseStore(object):
if not res:
return None
js, redacted = res
internal_metadata, js, redacted = res
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:
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(
event_id TEXT NOT NULL,
room_id TEXT NOT NULL,
internal_metadata NOT NULL,
json BLOB NOT NULL,
CONSTRAINT ev_j_uniq UNIQUE (event_id)
);