send info in chunks

This commit is contained in:
j 2013-07-27 20:49:50 +02:00
parent 70463c4b8a
commit 313d2d2486

View file

@ -242,8 +242,11 @@ class Client(object):
break break
return info return info
def get_info(self, oshash): def get_info(self, oshash, prefix=None):
prefixes = self.active_volumes().values() if prefix:
prefixes = [prefix]
else:
prefixes = self.active_volumes().values()
_info = self.info(oshash) _info = self.info(oshash)
for path in self.path(oshash): for path in self.path(oshash):
for prefix in prefixes: for prefix in prefixes:
@ -257,10 +260,10 @@ class Client(object):
print 'failed to parse', path print 'failed to parse', path
return return
def get_info_for_ids(self, ids): def get_info_for_ids(self, ids, prefix=None):
info = {} info = {}
for oshash in ids: for oshash in ids:
i = self.get_info(oshash) i = self.get_info(oshash, prefix)
if i: if i:
info[oshash] = i info[oshash] = i
return info return info
@ -580,16 +583,7 @@ class Client(object):
sent = 0 sent = 0
for offset in range(0, total, max_info): for offset in range(0, total, max_info):
post = {'info': {}, 'upload': True} post = {'info': {}, 'upload': True}
for oshash in info[offset:offset+max_info]: post['info'] = self.get_info_for_ids(info[offset:offset+max_info], prefix)
_info = self.info(oshash)
for path in self.path(oshash):
path = path[len(prefix):]
i = parse_path(self, path)
if i:
_info.update(i)
break
if _info:
post['info'][oshash] = _info
if len(post['info']): if len(post['info']):
r = self.api.update(post) r = self.api.update(post)
sent += len(post['info']) sent += len(post['info'])
@ -658,10 +652,17 @@ class Client(object):
if info: if info:
print 'info for %d files requested' % len(info) print 'info for %d files requested' % len(info)
post = {'info': get_info_for_ids(info)} max_info = 100
if post['info']: total = len(info)
print 'uploading info for %d files' % len(post['info']) sent = 0
r = self.api.update(post) for offset in range(0, total, max_info):
post = {'info': {}, 'upload': True}
post['info'] = self.get_info_for_ids(info[offset:offset+max_info])
if len(post['info']):
r = self.api.update(post)
sent += len(post['info'])
if sent:
print 'uploading info for %d files' % sent
if data: if data:
print 'encoding and uploading %s videos' % len(data) print 'encoding and uploading %s videos' % len(data)