Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/multiplexer/multiplexer_objstorage.py
Show First 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | def add(self, content, obj_id=None, check_presence=True): | ||||
obj_id=obj_id, check_presence=check_presence, | obj_id=obj_id, check_presence=check_presence, | ||||
).pop() | ).pop() | ||||
def add_batch(self, contents, check_presence=True): | def add_batch(self, contents, check_presence=True): | ||||
"""Add a batch of new objects to the object storage. | """Add a batch of new objects to the object storage. | ||||
""" | """ | ||||
write_threads = list(self.get_write_threads()) | write_threads = list(self.get_write_threads()) | ||||
return sum(self.wrap_call( | results = self.wrap_call( | ||||
write_threads, 'add_batch', contents, | write_threads, 'add_batch', contents, | ||||
check_presence=check_presence, | check_presence=check_presence, | ||||
)) // len(write_threads) | ) | ||||
object_add = 0 | |||||
object_add_bytes = 0 | |||||
for result in results: | |||||
object_add += result['object:add'] | |||||
object_add_bytes += result['object:add:bytes'] | |||||
return { | |||||
'object:add': object_add // len(result), | |||||
'object:add:bytes': object_add_bytes // len(result), | |||||
} | |||||
vlorentz: @olasd mentionned using a Counter, to get shorter code. I think it could work like this:
```… | |||||
vlorentzUnsubmitted Not Done Inline Actionsalso, s/result/results in the sum vlorentz: also, s/result/results in the sum | |||||
ardumontAuthorUnsubmitted Done Inline Actionsyeah... that's the real issue here ;) ardumont: yeah...
that's the real issue here ;) | |||||
Not Done Inline Actionsyou replaced a mean with the first result vlorentz: you replaced a mean with the first result | |||||
Done Inline ActionsThanks! ardumont: Thanks! | |||||
def restore(self, content, obj_id=None): | def restore(self, content, obj_id=None): | ||||
return self.wrap_call( | return self.wrap_call( | ||||
self.get_write_threads(obj_id), 'restore', content, obj_id=obj_id, | self.get_write_threads(obj_id), 'restore', content, obj_id=obj_id, | ||||
).pop() | ).pop() | ||||
def get(self, obj_id): | def get(self, obj_id): | ||||
for storage in self.get_read_threads(obj_id): | for storage in self.get_read_threads(obj_id): | ||||
try: | try: | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
@olasd mentionned using a Counter, to get shorter code. I think it could work like this: