Skip to content

Commit 0a27a3f

Browse files
Copilotdkropachev
andcommitted
Remove unnecessary paging_state save/restore per review
Since each QueryMessage is created fresh and only used once with _fetch_remaining_pages, there's no need to save and restore the original paging_state. The QueryMessage objects are not reused after calling _fetch_remaining_pages. Addresses @dkropachev's review feedback to verify the function isn't called multiple times on the same query_msg and remove the unnecessary save/restore code. Co-authored-by: dkropachev <40304587+dkropachev@users.noreply.github.com>
1 parent 2d1a49b commit 0a27a3f

1 file changed

Lines changed: 17 additions & 24 deletions

File tree

cassandra/cluster.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3451,32 +3451,25 @@ def _fetch_remaining_pages(connection, query_msg, timeout):
34513451
:param timeout: Timeout for each query operation
34523452
:return: The result with all parsed_rows combined from all pages
34533453
"""
3454-
# Save original paging_state to restore later
3455-
original_paging_state = query_msg.paging_state
3454+
# Execute the query to get the first page
3455+
result = connection.wait_for_response(query_msg, timeout=timeout)
34563456

3457-
try:
3458-
# Execute the query to get the first page
3459-
result = connection.wait_for_response(query_msg, timeout=timeout)
3460-
3461-
if not result or not result.paging_state:
3462-
return result
3463-
3464-
all_rows = list(result.parsed_rows) if result.parsed_rows else []
3465-
3466-
# Fetch remaining pages
3467-
while result and result.paging_state:
3468-
query_msg.paging_state = result.paging_state
3469-
result = connection.wait_for_response(query_msg, timeout=timeout)
3470-
if result and result.parsed_rows:
3471-
all_rows.extend(result.parsed_rows)
3472-
3473-
# Update the result with all rows
3474-
if result:
3475-
result.parsed_rows = all_rows
3457+
if not result or not result.paging_state:
34763458
return result
3477-
finally:
3478-
# Restore original paging_state to prevent affecting subsequent uses of this QueryMessage
3479-
query_msg.paging_state = original_paging_state
3459+
3460+
all_rows = list(result.parsed_rows) if result.parsed_rows else []
3461+
3462+
# Fetch remaining pages
3463+
while result and result.paging_state:
3464+
query_msg.paging_state = result.paging_state
3465+
result = connection.wait_for_response(query_msg, timeout=timeout)
3466+
if result and result.parsed_rows:
3467+
all_rows.extend(result.parsed_rows)
3468+
3469+
# Update the result with all rows
3470+
if result:
3471+
result.parsed_rows = all_rows
3472+
return result
34803473

34813474

34823475
class ControlConnection(object):

0 commit comments

Comments
 (0)