Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Move outlier out of InternalMetadata._dict
Browse files Browse the repository at this point in the history
Ultimately, this will allow us to stop writing it to the database. For now, we
have to grandfather it back in so as to maintain compatibility with older
versions of Synapse.
  • Loading branch information
richvdh committed Feb 15, 2021
1 parent fef287e commit c5a0417
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 6 additions & 3 deletions synapse/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __get__(self, instance, owner=None):


class _EventInternalMetadata:
__slots__ = ["_dict", "stream_ordering"]
__slots__ = ["_dict", "stream_ordering", "outlier"]

def __init__(self, internal_metadata_dict: JsonDict):
# we have to copy the dict, because it turns out that the same dict is
Expand All @@ -108,7 +108,10 @@ def __init__(self, internal_metadata_dict: JsonDict):
# the stream ordering of this event. None, until it has been persisted.
self.stream_ordering = None # type: Optional[int]

outlier = DictProperty("outlier") # type: bool
# whether this event is an outlier (ie, whether we have the state at that point
# in the DAG)
self.outlier = False

out_of_band_membership = DictProperty("out_of_band_membership") # type: bool
send_on_behalf_of = DictProperty("send_on_behalf_of") # type: str
recheck_redaction = DictProperty("recheck_redaction") # type: bool
Expand All @@ -129,7 +132,7 @@ def get_dict(self) -> JsonDict:
return dict(self._dict)

def is_outlier(self) -> bool:
return self._dict.get("outlier", False)
return self.outlier

def is_out_of_band_membership(self) -> bool:
"""Whether this is an out of band membership, like an invite or an invite
Expand Down
2 changes: 2 additions & 0 deletions synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def prune_event(event: EventBase) -> EventBase:
event.internal_metadata.stream_ordering
)

pruned_event.internal_metadata.outlier = event.internal_metadata.outlier

# Mark the event as redacted
pruned_event.internal_metadata.redacted = True

Expand Down
12 changes: 10 additions & 2 deletions synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,8 +1245,10 @@ def _update_outliers_txn(self, txn, events_and_contexts):
logger.exception("")
raise

# update the stored internal_metadata to update the "outlier" flag.
# TODO: This is unused as of Synapse 1.29. Remove it once we are happy
# to drop backwards-compatibility with 1.28.
metadata_json = json_encoder.encode(event.internal_metadata.get_dict())

sql = "UPDATE event_json SET internal_metadata = ? WHERE event_id = ?"
txn.execute(sql, (metadata_json, event.event_id))

Expand Down Expand Up @@ -1294,6 +1296,12 @@ def event_dict(event):
d.pop("redacted_because", None)
return d

def get_internal_metadata(event):
# temporary hack for compatibility with Synapse 1.28 and earlier
im = event.internal_metadata.get_dict()
im["outlier"] = event.internal_metadata.outlier
return im

self.db_pool.simple_insert_many_txn(
txn,
table="event_json",
Expand All @@ -1302,7 +1310,7 @@ def event_dict(event):
"event_id": event.event_id,
"room_id": event.room_id,
"internal_metadata": json_encoder.encode(
event.internal_metadata.get_dict()
get_internal_metadata(event)
),
"json": json_encoder.encode(event_dict(event)),
"format_version": event.format_version,
Expand Down

0 comments on commit c5a0417

Please sign in to comment.