Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
# Copyright (C) 2015-2020 The Software Heritage developers | # Copyright (C) 2015-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from collections import defaultdict | from collections import defaultdict | ||||
import datetime | import datetime | ||||
import functools | import functools | ||||
import itertools | |||||
import random | import random | ||||
from typing import ( | from typing import ( | ||||
Any, | Any, | ||||
Dict, | Dict, | ||||
Generic, | Generic, | ||||
Iterable, | Iterable, | ||||
Iterator, | Iterator, | ||||
List, | List, | ||||
▲ Show 20 Lines • Show All 279 Lines • ▼ Show 20 Lines | def directory_entry_add_one(self, entry: DirectoryEntryRow) -> None: | ||||
self._directory_entries.insert(entry) | self._directory_entries.insert(entry) | ||||
def directory_entry_get( | def directory_entry_get( | ||||
self, directory_ids: List[Sha1Git] | self, directory_ids: List[Sha1Git] | ||||
) -> Iterable[DirectoryEntryRow]: | ) -> Iterable[DirectoryEntryRow]: | ||||
for id_ in directory_ids: | for id_ in directory_ids: | ||||
yield from self._directory_entries.get_from_partition_key((id_,)) | yield from self._directory_entries.get_from_partition_key((id_,)) | ||||
def directory_entry_get_from_name( | |||||
self, directory_id: Sha1Git, from_: bytes, limit: int | |||||
) -> Iterable[DirectoryEntryRow]: | |||||
# Get all entries | |||||
entries = self._directory_entries.get_from_partition_key((directory_id,)) | |||||
# Filter out the ones before from_ | |||||
entries = itertools.dropwhile(lambda entry: entry.name < from_, entries) | |||||
# Apply limit | |||||
return itertools.islice(entries, limit) | |||||
########################## | ########################## | ||||
# 'revision' table | # 'revision' table | ||||
########################## | ########################## | ||||
def revision_missing(self, ids: List[bytes]) -> Iterable[bytes]: | def revision_missing(self, ids: List[bytes]) -> Iterable[bytes]: | ||||
missing = [] | missing = [] | ||||
for id_ in ids: | for id_ in ids: | ||||
if self._revisions.get_from_primary_key((id_,)) is None: | if self._revisions.get_from_primary_key((id_,)) is None: | ||||
▲ Show 20 Lines • Show All 377 Lines • Show Last 20 Lines |