Skip to content

Commit 37cbeb8

Browse files
committed
cache distance function for speed & readability
1 parent 3bf46dd commit 37cbeb8

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

cassandra/metadata.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2594,6 +2594,8 @@ def group_keys_by_replica(session, keyspace, table, keys):
25942594

25952595
serializers = list(types._cqltypes[partition_key.cql_type] for partition_key in partition_keys)
25962596
keys_per_host = defaultdict(list)
2597+
distance = cluster._default_load_balancing_policy.distance
2598+
25972599
for key in keys:
25982600
serialized_key = [serializer.serialize(pk, cluster.protocol_version)
25992601
for serializer, pk in zip(serializers, key)]
@@ -2604,8 +2606,7 @@ def group_keys_by_replica(session, keyspace, table, keys):
26042606
all_replicas = cluster.metadata.get_replicas(keyspace, routing_key)
26052607
# First check if there are local replicas
26062608
valid_replicas = [host for host in all_replicas if
2607-
host.is_up and cluster._default_load_balancing_policy.distance(
2608-
host) == HostDistance.LOCAL]
2609+
host.is_up and distance(host) == HostDistance.LOCAL]
26092610
if not valid_replicas:
26102611
valid_replicas = [host for host in all_replicas if host.is_up]
26112612

0 commit comments

Comments
 (0)