Changeset View
Changeset View
Standalone View
Standalone View
swh/provenance/postgresql/archive.py
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | def revision_get_parents(self, id: Sha1Git) -> Iterable[Sha1Git]: | ||||
for row in cursor.fetchall(): | for row in cursor.fetchall(): | ||||
yield from row[0] | yield from row[0] | ||||
def snapshot_get_heads(self, id: Sha1Git) -> Iterable[Sha1Git]: | def snapshot_get_heads(self, id: Sha1Git) -> Iterable[Sha1Git]: | ||||
with self.conn.cursor() as cursor: | with self.conn.cursor() as cursor: | ||||
cursor.execute( | cursor.execute( | ||||
""" | """ | ||||
WITH S AS (SELECT object_id FROM snapshot WHERE snapshot.id=%s) | WITH S AS (SELECT object_id FROM snapshot WHERE snapshot.id=%s) | ||||
(SELECT B.target AS head | (SELECT R.id AS head, R.date AS date | ||||
FROM S | FROM S | ||||
JOIN snapshot_branches AS BS ON (S.object_id=BS.snapshot_id) | JOIN snapshot_branches AS BS ON (S.object_id=BS.snapshot_id) | ||||
JOIN snapshot_branch AS B ON (BS.branch_id=B.object_id) | JOIN snapshot_branch AS B ON (BS.branch_id=B.object_id) | ||||
JOIN revision AS R ON (B.target=R.id) | |||||
WHERE B.target_type='revision'::snapshot_target) | WHERE B.target_type='revision'::snapshot_target) | ||||
UNION | UNION | ||||
(SELECT R.target AS head | (SELECT RV.id AS head, RV.date AS date | ||||
FROM S | FROM S | ||||
JOIN snapshot_branches AS BS ON (S.object_id=BS.snapshot_id) | JOIN snapshot_branches AS BS ON (S.object_id=BS.snapshot_id) | ||||
JOIN snapshot_branch AS B ON (BS.branch_id=B.object_id) | JOIN snapshot_branch AS B ON (BS.branch_id=B.object_id) | ||||
JOIN release AS R ON (B.target=R.id) | JOIN release AS RL ON (B.target=RL.id) | ||||
JOIN revision AS RV ON (RL.target=RV.id) | |||||
WHERE B.target_type='release'::snapshot_target | WHERE B.target_type='release'::snapshot_target | ||||
AND R.target_type='revision'::object_type) | AND RL.target_type='revision'::object_type) | ||||
ORDER BY date, head | |||||
""", | """, | ||||
(id,), | (id,), | ||||
) | ) | ||||
heads = [row[0] for row in cursor.fetchall()] | yield from (head for head, _ in cursor.fetchall()) | ||||
douardda: (a bit nitpick but) since you do not need the dates to be returned, the SQL query should not… | |||||
print([head.hex() for head in heads]) | |||||
yield from heads | |||||
# for row in cursor.fetchall(): | |||||
# yield row[0] |
(a bit nitpick but) since you do not need the dates to be returned, the SQL query should not select them.