Skip to content

Commit 29085d5

Browse files
committed
Fixed length not calculed twice
1 parent cf865ce commit 29085d5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

graphql_relay/connection/arrayconnection.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ def connection_from_list(data, args=None, **kwargs):
1010
a connection object for use in GraphQL. It uses array offsets as pagination,
1111
so pagination will only work if the array is static.
1212
'''
13+
_len = len(data)
1314
return connection_from_list_slice(
1415
data,
1516
args,
1617
slice_start=0,
17-
list_length=len(data),
18+
list_length=_len,
19+
list_slice_length=_len,
1820
**kwargs
1921
)
2022

@@ -29,7 +31,7 @@ def connection_from_promised_list(data_promise, args=None, **kwargs):
2931

3032
def connection_from_list_slice(list_slice, args=None, connection_type=None,
3133
edge_type=None, pageinfo_type=None,
32-
slice_start=0, list_length=0):
34+
slice_start=0, list_length=0, list_slice_length=None):
3335
'''
3436
Given a slice (subset) of an array, returns a connection object for use in
3537
GraphQL.
@@ -48,7 +50,8 @@ def connection_from_list_slice(list_slice, args=None, connection_type=None,
4850
after = args.get('after')
4951
first = args.get('first')
5052
last = args.get('last')
51-
list_slice_length = len(list_slice)
53+
if list_slice_length is None:
54+
list_slice_length = len(list_slice)
5255
slice_end = slice_start + list_slice_length
5356
before_offset = get_offset_with_default(before, list_length)
5457
after_offset = get_offset_with_default(after, -1)

0 commit comments

Comments
 (0)