diff --git a/swh/provenance/postgresql/provenancedb.py b/swh/provenance/postgresql/provenancedb.py index 7276daf..8c626c5 100644 --- a/swh/provenance/postgresql/provenancedb.py +++ b/swh/provenance/postgresql/provenancedb.py @@ -304,10 +304,8 @@ class ProvenanceDB: sha1s: Optional[Tuple[Tuple[Sha1Git, ...]]] if ids is not None: sha1s = (tuple(ids),) - where = f"WHERE {'S' if not reverse else 'D'}.sha1 IN %s" else: sha1s = None - where = "" aggreg_dst = self.denormalized and relation in ( RelationType.CNT_EARLY_IN_REV, @@ -339,9 +337,9 @@ class ProvenanceDB: SELECT S.sha1 AS src, {revloc} FROM {table} AS R INNER JOIN {src} AS S ON (S.id=R.{src_field}) - {where} """ - + if sha1s and not reverse: + inner_sql += "WHERE S.sha1 IN %s\n" if self._relation_uses_location_table(relation): loc = "L.path AS path" else: @@ -352,7 +350,9 @@ class ProvenanceDB: INNER JOIN {dst} AS D ON (D.id=CL.dst) """ if self._relation_uses_location_table(relation): - sql += "INNER JOIN location AS L ON (L.id=CL.path)" + sql += "INNER JOIN location AS L ON (L.id=CL.path)\n" + if sha1s and reverse: + sql += "WHERE D.sha1 IN %s\n" self.cursor.execute(sql, sha1s) result.update(RelationData(**row) for row in self.cursor.fetchall()