mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 11:06:07 -04:00
Move pdu and event persistence into a single persist_event function
This commit is contained in:
parent
66a4d33524
commit
64e2a5d58e
4 changed files with 36 additions and 50 deletions
|
@ -25,7 +25,6 @@ from .units import Pdu
|
|||
|
||||
from synapse.util.logutils import log_function
|
||||
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
|
||||
|
@ -48,9 +47,8 @@ class PduActions(object):
|
|||
Returns:
|
||||
Deferred
|
||||
"""
|
||||
return self._persist(pdu)
|
||||
return self.store.persist_event(pdu=pdu)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
@log_function
|
||||
def persist_outgoing(self, pdu):
|
||||
""" Persists the given `Pdu` that this home server created.
|
||||
|
@ -58,9 +56,7 @@ class PduActions(object):
|
|||
Returns:
|
||||
Deferred
|
||||
"""
|
||||
ret = yield self._persist(pdu)
|
||||
|
||||
defer.returnValue(ret)
|
||||
return self.store.persist_event(pdu=pdu)
|
||||
|
||||
@log_function
|
||||
def mark_as_processed(self, pdu):
|
||||
|
@ -143,28 +139,6 @@ class PduActions(object):
|
|||
depth=pdu.depth
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
@log_function
|
||||
def _persist(self, pdu):
|
||||
kwargs = copy.copy(pdu.__dict__)
|
||||
unrec_keys = copy.copy(pdu.unrecognized_keys)
|
||||
del kwargs["content"]
|
||||
kwargs["content_json"] = json.dumps(pdu.content)
|
||||
kwargs["unrecognized_keys"] = json.dumps(unrec_keys)
|
||||
|
||||
logger.debug("Persisting: %s", repr(kwargs))
|
||||
|
||||
if pdu.is_state:
|
||||
ret = yield self.store.persist_state(**kwargs)
|
||||
else:
|
||||
ret = yield self.store.persist_pdu(**kwargs)
|
||||
|
||||
yield self.store.update_min_depth_for_context(
|
||||
pdu.context, pdu.depth
|
||||
)
|
||||
|
||||
defer.returnValue(ret)
|
||||
|
||||
|
||||
class TransactionActions(object):
|
||||
""" Defines persistence actions that relate to handling Transactions.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue