Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/storage.py
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
from ..exc import HashCollision, StorageArgumentException | from ..exc import HashCollision, StorageArgumentException | ||||
from ..utils import remove_keys | from ..utils import remove_keys | ||||
from .common import TOKEN_BEGIN, TOKEN_END, hash_url | from .common import TOKEN_BEGIN, TOKEN_END, hash_url | ||||
from .cql import CqlRunner | from .cql import CqlRunner | ||||
from .model import ( | from .model import ( | ||||
ContentRow, | ContentRow, | ||||
DirectoryEntryRow, | DirectoryEntryRow, | ||||
DirectoryRow, | DirectoryRow, | ||||
ExtIDByTargetRow, | |||||
ExtIDRow, | ExtIDRow, | ||||
MetadataAuthorityRow, | MetadataAuthorityRow, | ||||
MetadataFetcherRow, | MetadataFetcherRow, | ||||
OriginRow, | OriginRow, | ||||
OriginVisitRow, | OriginVisitRow, | ||||
OriginVisitStatusRow, | OriginVisitStatusRow, | ||||
RawExtrinsicMetadataRow, | RawExtrinsicMetadataRow, | ||||
RevisionParentRow, | RevisionParentRow, | ||||
▲ Show 20 Lines • Show All 1,269 Lines • ▼ Show 20 Lines | def extid_add(self, ids: List[ExtID]) -> Dict[str, int]: | ||||
extid_type=extid.extid_type, extid=extid.extid, target=extid.target, | extid_type=extid.extid_type, extid=extid.extid, target=extid.target, | ||||
) | ) | ||||
] | ] | ||||
self.journal_writer.extid_add(extids) | self.journal_writer.extid_add(extids) | ||||
inserted = 0 | inserted = 0 | ||||
for extid in extids: | for extid in extids: | ||||
target_type = extid.target.object_type.value | |||||
target = extid.target.object_id | |||||
extidrow = ExtIDRow( | extidrow = ExtIDRow( | ||||
extid_type=extid.extid_type, | extid_type=extid.extid_type, | ||||
extid=extid.extid, | extid=extid.extid, | ||||
target_type=extid.target.object_type.value, | target_type=target_type, | ||||
target=extid.target.object_id, | target=target, | ||||
) | ) | ||||
(token, insertion_finalizer) = self._cql_runner.extid_add_prepare(extidrow) | (token, insertion_finalizer) = self._cql_runner.extid_add_prepare(extidrow) | ||||
self._cql_runner.extid_index_add_one(extidrow, token) | indexrow = ExtIDByTargetRow( | ||||
target_type=target_type, target=target, target_token=token, | |||||
) | |||||
self._cql_runner.extid_index_add_one(indexrow) | |||||
insertion_finalizer() | insertion_finalizer() | ||||
inserted += 1 | inserted += 1 | ||||
return {"extid:add": inserted} | return {"extid:add": inserted} | ||||
def extid_get_from_extid(self, id_type: str, ids: List[bytes]) -> List[ExtID]: | def extid_get_from_extid(self, id_type: str, ids: List[bytes]) -> List[ExtID]: | ||||
result: List[ExtID] = [] | result: List[ExtID] = [] | ||||
for extid in ids: | for extid in ids: | ||||
extidrows = list(self._cql_runner.extid_get_from_extid(id_type, extid)) | extidrows = list(self._cql_runner.extid_get_from_extid(id_type, extid)) | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |