@@ -363,7 +363,11 @@ def _get_snapshots(
363363 query = (
364364 exp .select (exp .column ("snapshot" , table = "snapshots" ))
365365 .from_ (exp .to_table (self .snapshots_table ).as_ ("snapshots" ))
366- .where (self ._snapshot_id_filter (snapshot_ids , "snapshots" ) if snapshot_ids else None )
366+ .where (
367+ None
368+ if snapshot_ids is None
369+ else self ._snapshot_id_filter (snapshot_ids , "snapshots" )
370+ )
367371 )
368372 if hydrate_seeds :
369373 query = query .select (exp .column ("content" , table = "seeds" )).join (
@@ -411,7 +415,7 @@ def _get_snapshots(
411415
412416 def _get_snapshots_with_same_version (
413417 self ,
414- snapshots : t .Iterable [SnapshotNameVersionLike ],
418+ snapshots : t .Collection [SnapshotNameVersionLike ],
415419 lock_for_update : bool = False ,
416420 ) -> t .List [Snapshot ]:
417421 """Fetches all snapshots that share the same version as the snapshots.
@@ -906,7 +910,11 @@ def map_data_versions(
906910 def _snapshot_id_filter (
907911 self , snapshot_ids : t .Iterable [SnapshotIdLike ], alias : t .Optional [str ] = None
908912 ) -> t .Union [exp .In , exp .Boolean , exp .Condition ]:
909- if not snapshot_ids :
913+ name_identifiers = {
914+ (snapshot_id .name , snapshot_id .identifier ) for snapshot_id in snapshot_ids
915+ }
916+
917+ if not name_identifiers :
910918 return exp .false ()
911919 elif self .engine_adapter .SUPPORTS_TUPLE_IN :
912920 return t .cast (
@@ -917,22 +925,24 @@ def _snapshot_id_filter(
917925 exp .column ("identifier" , table = alias ),
918926 )
919927 ),
920- ).isin (* [( snapshot_id . name , snapshot_id . identifier ) for snapshot_id in snapshot_ids ] )
928+ ).isin (* name_identifiers )
921929 else :
922930 return exp .or_ (
923931 * [
924932 exp .and_ (
925- exp .column ("name" , table = alias ).eq (snapshot_id . name ),
926- exp .column ("identifier" , table = alias ).eq (snapshot_id . identifier ),
933+ exp .column ("name" , table = alias ).eq (name ),
934+ exp .column ("identifier" , table = alias ).eq (identifier ),
927935 )
928- for snapshot_id in snapshot_ids
936+ for name , identifier in name_identifiers
929937 ]
930938 )
931939
932940 def _snapshot_name_version_filter (
933941 self , snapshot_name_versions : t .Iterable [SnapshotNameVersionLike ], alias : str = "snapshots"
934942 ) -> t .Union [exp .In , exp .Boolean , exp .Condition ]:
935- if not snapshot_name_versions :
943+ name_versions = {(s .name , s .version ) for s in snapshot_name_versions }
944+
945+ if not name_versions :
936946 return exp .false ()
937947 elif self .engine_adapter .SUPPORTS_TUPLE_IN :
938948 return t .cast (
@@ -943,20 +953,15 @@ def _snapshot_name_version_filter(
943953 exp .column ("version" , table = alias ),
944954 )
945955 ),
946- ).isin (
947- * [
948- (snapshot_name_version .name , snapshot_name_version .version )
949- for snapshot_name_version in snapshot_name_versions
950- ]
951- )
956+ ).isin (* name_versions )
952957 else :
953958 return exp .or_ (
954959 * [
955960 exp .and_ (
956- exp .column ("name" , table = alias ).eq (snapshot_name_version . name ),
957- exp .column ("version" , table = alias ).eq (snapshot_name_version . version ),
961+ exp .column ("name" , table = alias ).eq (name ),
962+ exp .column ("version" , table = alias ).eq (version ),
958963 )
959- for snapshot_name_version in snapshot_name_versions
964+ for name , version in name_versions
960965 ]
961966 )
962967
0 commit comments