Skip to content

Commit f7d7b60

Browse files
committed
Migrate to serialize stream
1 parent e007310 commit f7d7b60

3 files changed

Lines changed: 118 additions & 282 deletions

File tree

morango/sync/controller.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,35 @@
66
from morango.constants import transfer_statuses
77
from morango.registry import session_middleware
88
from morango.sync.operations import _deserialize_from_store
9-
from morango.sync.operations import _serialize_into_store
109
from morango.sync.operations import OperationLogger
10+
from morango.sync.stream.serialize import serialize_into_store
1111
from morango.sync.utils import SyncSignalGroup
1212
from morango.utils import _assert
1313

14-
1514
logger = logging.getLogger(__name__)
1615

1716

18-
def _self_referential_fk(klass_model):
19-
"""
20-
Return whether this model has a self ref FK, and the name for the field
21-
"""
22-
for f in klass_model._meta.concrete_fields:
23-
if f.related_model:
24-
if issubclass(klass_model, f.related_model):
25-
return f.attname
26-
return None
27-
28-
2917
class MorangoProfileController(object):
3018
def __init__(self, profile):
3119
_assert(profile, "profile needs to be defined.")
3220
self.profile = profile
3321

34-
def serialize_into_store(self, filter=None):
22+
def serialize_into_store(self, sync_filter=None):
3523
"""
3624
Takes data from app layer and serializes the models into the store.
3725
"""
3826
with OperationLogger("Serializing records", "Serialization complete"):
39-
_serialize_into_store(self.profile, filter=filter)
27+
serialize_into_store(self.profile, sync_filter=sync_filter)
4028

41-
def deserialize_from_store(self, skip_erroring=False, filter=None):
29+
def deserialize_from_store(self, skip_erroring=False, sync_filter=None):
4230
"""
4331
Takes data from the store and integrates into the application.
4432
"""
4533
with OperationLogger("Deserializing records", "Deserialization complete"):
4634
# we first serialize to avoid deserialization merge conflicts
47-
_serialize_into_store(self.profile, filter=filter)
35+
serialize_into_store(self.profile, sync_filter=sync_filter)
4836
_deserialize_from_store(
49-
self.profile, filter=filter, skip_erroring=skip_erroring
37+
self.profile, filter=sync_filter, skip_erroring=skip_erroring
5038
)
5139

5240
def create_network_connection(self, base_url, **kwargs):
@@ -217,7 +205,7 @@ def proceed_to_and_wait_for(
217205
if tries >= max_interval_tries:
218206
sleep(max_interval)
219207
else:
220-
sleep(0.3 * (2 ** tries - 1))
208+
sleep(0.3 * (2**tries - 1))
221209
result = self.proceed_to(target_stage, context=context)
222210
tries += 1
223211
if callable(callback):

0 commit comments

Comments
 (0)