storage: load/save index files as binary files (#36515)

This commit is contained in:
Frédéric Péters 2019-11-12 14:56:27 +01:00
parent 4fced111d6
commit 6d80317832
1 changed files with 8 additions and 8 deletions

View File

@ -364,7 +364,7 @@ class StorableObject(object):
return [x for x in values if getattr(x, index) == value]
if not os.path.exists(index_file):
return []
return pickle.load(file(index_file))
return pickle.load(open(index_file, 'rb'))
@classmethod
def get_with_indexed_value(cls, index, value, ignore_errors = False):
@ -491,7 +491,7 @@ class StorableObject(object):
if index_key not in indexes:
continue
index_file = os.path.join(objects_dir, '.indexes', index_key, index)
pickle.dump(content, file(index_file, 'w'), protocol=2)
pickle.dump(content, open(index_file, 'wb'), protocol=2)
for index in cls._hashed_indexes or []:
if index not in indexes:
@ -674,10 +674,10 @@ class StorableObject(object):
old_index_name = '%s-%s' % (index, fix_key(oldv))
old_index_file = os.path.join(index_dir, old_index_name)
if os.path.exists(old_index_file):
ids = [str(x) for x in pickle.load(file(old_index_file))]
ids = [str(x) for x in pickle.load(open(old_index_file, 'rb'))]
if str(self.id) in ids:
ids.remove(str(self.id))
pickle.dump(ids, file(old_index_file, 'w'), protocol=2)
pickle.dump(ids, open(old_index_file, 'wb'), protocol=2)
for newv in new_value:
if newv in old_value:
@ -685,12 +685,12 @@ class StorableObject(object):
index_name = '%s-%s' % (index, fix_key(newv))
index_file = os.path.join(index_dir, index_name)
if os.path.exists(index_file):
ids = [str(x) for x in pickle.load(file(index_file))]
ids = [str(x) for x in pickle.load(open(index_file, 'rb'))]
else:
ids = []
if not str(self.id) in ids:
ids.append(str(self.id))
pickle.dump(ids, file(index_file, 'w'), protocol=2)
pickle.dump(ids, open(index_file, 'wb'), protocol=2)
@classmethod
def volatile(cls):
@ -724,10 +724,10 @@ class StorableObject(object):
index_name = '%s-%s' % (index, attr_value)
index_file = os.path.join(index_dir, index, index_name)
if os.path.exists(index_file):
ids = [str(x) for x in pickle.load(file(index_file))]
ids = [str(x) for x in pickle.load(open(index_file, 'rb'))]
if str(object.id) in ids:
ids.remove(str(object.id))
pickle.dump(ids, file(index_file, 'w'), protocol=2)
pickle.dump(ids, open(index_file, 'wb'), protocol=2)
os.unlink(os.path.join(objects_dir, fix_key(id)))