Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | def reset(self): | ||||
self.objstorage = get_objstorage('memory', {}) | self.objstorage = get_objstorage('memory', {}) | ||||
def check_config(self, *, check_write): | def check_config(self, *, check_write): | ||||
"""Check that the storage is configured and ready to go.""" | """Check that the storage is configured and ready to go.""" | ||||
return True | return True | ||||
def _content_add(self, contents, with_data): | def _content_add(self, contents, with_data): | ||||
if self.journal_writer: | |||||
for content in contents: | |||||
content = attr.evolve(content, data=None) | |||||
self.journal_writer.write_addition('content', content) | |||||
content_with_data = [] | content_with_data = [] | ||||
content_without_data = [] | content_without_data = [] | ||||
for content in contents: | for content in contents: | ||||
if content.status is None: | if content.status is None: | ||||
content.status = 'visible' | content.status = 'visible' | ||||
if content.length is None: | if content.length is None: | ||||
content.length = -1 | content.length = -1 | ||||
if content.status == 'visible': | if content.status == 'visible': | ||||
if self._content_key(content) not in self._contents: | |||||
content_with_data.append(content) | content_with_data.append(content) | ||||
elif content.status == 'absent': | elif content.status == 'absent': | ||||
if self._content_key(content) not in self._skipped_contents: | |||||
content_without_data.append(content) | content_without_data.append(content) | ||||
if self.journal_writer: | |||||
for content in content_with_data: | |||||
content = attr.evolve(content, data=None) | |||||
self.journal_writer.write_addition('content', content) | |||||
for content in content_without_data: | |||||
self.journal_writer.write_addition('content', content) | |||||
count_content_added, count_content_bytes_added = \ | count_content_added, count_content_bytes_added = \ | ||||
self._content_add_present(content_with_data, with_data) | self._content_add_present(content_with_data, with_data) | ||||
count_skipped_content_added = self._content_add_absent( | count_skipped_content_added = self._content_add_absent( | ||||
content_without_data | content_without_data | ||||
) | ) | ||||
summary = { | summary = { | ||||
▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | def directory_add(self, directories): | ||||
- perms (int): entry permissions | - perms (int): entry permissions | ||||
Returns: | Returns: | ||||
Summary dict of keys with associated count as values: | Summary dict of keys with associated count as values: | ||||
directory:add: Number of directories actually added | directory:add: Number of directories actually added | ||||
""" | """ | ||||
if self.journal_writer: | if self.journal_writer: | ||||
self.journal_writer.write_additions('directory', directories) | self.journal_writer.write_additions( | ||||
'directory', | |||||
(dir_ for dir_ in directories | |||||
if dir_['id'] not in self._directories)) | |||||
directories = [Directory.from_dict(d) for d in directories] | directories = [Directory.from_dict(d) for d in directories] | ||||
count = 0 | count = 0 | ||||
for directory in directories: | for directory in directories: | ||||
if directory.id not in self._directories: | if directory.id not in self._directories: | ||||
count += 1 | count += 1 | ||||
self._directories[directory.id] = directory | self._directories[directory.id] = directory | ||||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | def revision_add(self, revisions): | ||||
Returns: | Returns: | ||||
Summary dict of keys with associated count as values | Summary dict of keys with associated count as values | ||||
revision_added: New objects actually stored in db | revision_added: New objects actually stored in db | ||||
""" | """ | ||||
if self.journal_writer: | if self.journal_writer: | ||||
self.journal_writer.write_additions('revision', revisions) | self.journal_writer.write_additions( | ||||
'revision', | |||||
(rev for rev in revisions | |||||
if rev['id'] not in self._revisions)) | |||||
revisions = [Revision.from_dict(rev) for rev in revisions] | revisions = [Revision.from_dict(rev) for rev in revisions] | ||||
count = 0 | count = 0 | ||||
for revision in revisions: | for revision in revisions: | ||||
if revision.id not in self._revisions: | if revision.id not in self._revisions: | ||||
revision.committer = self._person_add(revision.committer) | revision.committer = self._person_add(revision.committer) | ||||
revision.author = self._person_add(revision.author) | revision.author = self._person_add(revision.author) | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | def release_add(self, releases): | ||||
Returns: | Returns: | ||||
Summary dict of keys with associated count as values | Summary dict of keys with associated count as values | ||||
release:add: New objects contents actually stored in db | release:add: New objects contents actually stored in db | ||||
""" | """ | ||||
if self.journal_writer: | if self.journal_writer: | ||||
self.journal_writer.write_additions('release', releases) | self.journal_writer.write_additions( | ||||
'release', | |||||
(rel for rel in releases | |||||
if rel['id'] not in self._releases)) | |||||
releases = [Release.from_dict(rel) for rel in releases] | releases = [Release.from_dict(rel) for rel in releases] | ||||
count = 0 | count = 0 | ||||
for rel in releases: | for rel in releases: | ||||
if rel.id not in self._releases: | if rel.id not in self._releases: | ||||
if rel.author: | if rel.author: | ||||
self._person_add(rel.author) | self._person_add(rel.author) | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | def snapshot_add(self, snapshots): | ||||
Returns: | Returns: | ||||
Summary dict of keys with associated count as values | Summary dict of keys with associated count as values | ||||
snapshot_added: Count of object actually stored in db | snapshot_added: Count of object actually stored in db | ||||
""" | """ | ||||
count = 0 | count = 0 | ||||
snapshots = (Snapshot.from_dict(d) for d in snapshots) | snapshots = (Snapshot.from_dict(d) for d in snapshots) | ||||
snapshots = (snap for snap in snapshots | snapshots = (snap for snap in snapshots | ||||
if snap.id not in self._snapshots) | if snap.id not in self._snapshots) | ||||
for snapshot in snapshots: | for snapshot in snapshots: | ||||
if snapshot.id in self._snapshots: | |||||
continue | |||||
olasd: This looks redundant | |||||
vlorentzAuthorUnsubmitted Done Inline ActionsGood catch. Same issue with the other methods. vlorentz: Good catch. Same issue with the other methods. | |||||
vlorentzAuthorUnsubmitted Done Inline ActionsActually, no, only in this one. vlorentz: Actually, no, only in this one. | |||||
if self.journal_writer: | if self.journal_writer: | ||||
self.journal_writer.write_addition('snapshot', snapshot) | self.journal_writer.write_addition('snapshot', snapshot) | ||||
sorted_branch_names = sorted(snapshot.branches) | sorted_branch_names = sorted(snapshot.branches) | ||||
self._snapshots[snapshot.id] = (snapshot, sorted_branch_names) | self._snapshots[snapshot.id] = (snapshot, sorted_branch_names) | ||||
self._objects[snapshot.id].append(('snapshot', snapshot.id)) | self._objects[snapshot.id].append(('snapshot', snapshot.id)) | ||||
count += 1 | count += 1 | ||||
▲ Show 20 Lines • Show All 951 Lines • Show Last 20 Lines |
This looks redundant