Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/postgresql/provenance.py
Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | def directory_get(self, ids: Iterable[Sha1Git]) -> Dict[Sha1Git, DirectoryData]: | ||||
with self.transaction(readonly=True) as cursor: | with self.transaction(readonly=True) as cursor: | ||||
cursor.execute(query=sql, vars=sha1s) | cursor.execute(query=sql, vars=sha1s) | ||||
result.update( | result.update( | ||||
(row["sha1"], DirectoryData(date=row["date"], flat=row["flat"])) | (row["sha1"], DirectoryData(date=row["date"], flat=row["flat"])) | ||||
for row in cursor | for row in cursor | ||||
) | ) | ||||
return result | return result | ||||
@statsd.timed( | |||||
metric=STORAGE_DURATION_METRIC, tags={"method": "directory_iter_not_flattenned"} | |||||
) | |||||
def directory_iter_not_flattenned( | |||||
self, limit: int, start_id: Sha1Git | |||||
) -> List[Sha1Git]: | |||||
sql = """ | |||||
SELECT sha1 FROM directory | |||||
WHERE flat=false AND sha1>%s ORDER BY sha1 LIMIT %s | |||||
""" | |||||
with self.transaction(readonly=True) as cursor: | |||||
cursor.execute(query=sql, vars=(start_id, limit)) | |||||
return [row["sha1"] for row in cursor] | |||||
@statsd.timed(metric=STORAGE_DURATION_METRIC, tags={"method": "entity_get_all"}) | @statsd.timed(metric=STORAGE_DURATION_METRIC, tags={"method": "entity_get_all"}) | ||||
def entity_get_all(self, entity: EntityType) -> Set[Sha1Git]: | def entity_get_all(self, entity: EntityType) -> Set[Sha1Git]: | ||||
with self.transaction(readonly=True) as cursor: | with self.transaction(readonly=True) as cursor: | ||||
cursor.execute(f"SELECT sha1 FROM {entity.value}") | cursor.execute(f"SELECT sha1 FROM {entity.value}") | ||||
return {row["sha1"] for row in cursor} | return {row["sha1"] for row in cursor} | ||||
@statsd.timed(metric=STORAGE_DURATION_METRIC, tags={"method": "location_add"}) | @statsd.timed(metric=STORAGE_DURATION_METRIC, tags={"method": "location_add"}) | ||||
@handle_raise_on_commit | @handle_raise_on_commit | ||||
▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines |