Skip to content

Commit 85c6ee8

Browse files
Copilotmykaul
andcommitted
Improve code comments for clarity on memory optimization
Co-authored-by: mykaul <4655593+mykaul@users.noreply.github.com>
1 parent ec8203e commit 85c6ee8

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

cassandra/policies.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,17 @@ def make_query_plan(self, working_keyspace=None, query=None):
506506

507507
child = self._child_policy
508508

509-
# Early return case: pass through the generator directly without materializing
509+
# Early return case: pass through the generator to preserve lazy evaluation
510+
# This avoids materializing the full host list in memory when we don't need token-aware routing
510511
if query is None or query.routing_key is None or keyspace is None:
511512
for host in child.make_query_plan(keyspace, query):
512513
yield host
513514
return
514515

515516
# Call child.make_query_plan only once and convert to list for reuse
516-
# This is necessary because we need to iterate over it multiple times
517+
# List conversion is necessary because we iterate over it twice:
518+
# 1. To identify replicas (either from tablets or token ring)
519+
# 2. To yield remaining hosts not in the replica set
517520
child_plan = list(child.make_query_plan(keyspace, query))
518521

519522
replicas = []

0 commit comments

Comments
 (0)