Skip to content

Commit e9e9a2c

Browse files
CopilotDonnieBLT
andcommitted
Improve comment explaining len() vs count() on sliced querysets
Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com>
1 parent d8bb5b4 commit e9e9a2c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

website/views/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,9 @@ def search(request, template="search.html"):
799799
result_count = 0
800800

801801
# Get result counts from context if available
802-
# Use len() instead of .count() to avoid additional DB queries on sliced querysets
802+
# Use len() instead of .count() on sliced querysets:
803+
# .count() on a sliced queryset first evaluates the slice and then counts,
804+
# making it redundant and potentially slower than just using len().
803805
try:
804806
if search_type == "all" or not search_type:
805807
# Sum counts from all search results

0 commit comments

Comments
 (0)