Fixed some bugs

This commit is contained in:
M1ha 2018-11-26 17:28:03 +05:00
parent e81a6b5e4a
commit 0e4dd6b69f
2 changed files with 16 additions and 7 deletions

View File

@ -119,6 +119,9 @@ class ClickHouseModel(with_metaclass(ClickHouseModelMeta, InfiModel)):
:param operations: A list of operations to perform
:return: A list of django_model instances
"""
if not operations:
return []
pk_by_db = defaultdict(set)
for op, pk_str in operations:
using, pk = pk_str.split('.')
@ -168,14 +171,15 @@ class ClickHouseModel(with_metaclass(ClickHouseModelMeta, InfiModel)):
with statsd.timer(statsd_key.format('get_operations')):
operations = storage.get_operations(import_key, cls.get_sync_batch_size())
with statsd.timer(statsd_key.format('get_sync_objects')):
import_objects = cls.get_sync_objects(operations)
if operations:
with statsd.timer(statsd_key.format('get_sync_objects')):
import_objects = cls.get_sync_objects(operations)
with statsd.timer(statsd_key.format('get_insert_batch')):
batch = cls.get_insert_batch(import_objects)
with statsd.timer(statsd_key.format('get_insert_batch')):
batch = cls.get_insert_batch(import_objects)
with statsd.timer(statsd_key.format('insert')):
cls.insert_batch(batch)
with statsd.timer(statsd_key.format('insert')):
cls.insert_batch(batch)
with statsd.timer(statsd_key.format('post_sync')):
storage.post_sync(import_key)

View File

@ -13,7 +13,12 @@ class Django2ClickHouseModelSerializer:
self.exclude_serialize_fields = exclude_fields
def serialize(self, obj): # type: (DjangoModel) -> 'ClickHouseModel'
data = model_to_dict(obj, self.serialize_fields, self.exclude_serialize_fields)
# Standard model_to_dict ignores some fields if they have invalid naming
data = {}
for name in set(self.serialize_fields) - set(self.exclude_serialize_fields):
val = getattr(obj, name, None)
if val is not None:
data[name] = val
# Remove None values, they should be initialized as defaults
params = {}