Skip to content

Commit 31f9db2

Browse files
committed
return back a PaginatedCollection in get_data_row_ids
1 parent 2515b2e commit 31f9db2

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

labelbox/schema/slice.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from typing import List
2-
31
from labelbox.orm.db_object import DbObject
42
from labelbox.orm.model import Field
3+
from labelbox.pagination import PaginatedCollection
54

65

76
class Slice(DbObject):
@@ -27,18 +26,19 @@ class CatalogSlice(Slice):
2726
Represents a Slice used for filtering data rows in Catalog.
2827
"""
2928

30-
def get_data_row_ids(self) -> List[str]:
29+
def get_data_row_ids(self) -> PaginatedCollection:
3130
"""
3231
Fetches all data row ids that match this Slice
3332
3433
Returns:
35-
A list of data row ids
34+
A PaginatedCollection of data row ids
3635
"""
3736
query_str = """
38-
query getDataRowIdsBySavedQueryPyApi($id: ID!, $after: String) {
37+
query getDataRowIdsBySavedQueryPyApi($id: ID!, $from: String, $first: Int!) {
3938
getDataRowIdsBySavedQuery(input: {
4039
savedQueryId: $id,
41-
after: $after
40+
after: $from
41+
first: $first
4242
}) {
4343
totalCount
4444
nodes
@@ -49,19 +49,10 @@ def get_data_row_ids(self) -> List[str]:
4949
}
5050
}
5151
"""
52-
data_row_ids: List[str] = []
53-
total_count = 0
54-
end_cursor = None
55-
has_next_page = True
56-
while has_next_page:
57-
res = self.client.execute(query_str, {
58-
'id': self.uid,
59-
'after': end_cursor
60-
})['getDataRowIdsBySavedQuery']
61-
data_row_ids = data_row_ids + res['nodes']
62-
total_count = res['totalCount']
63-
has_next_page = res['pageInfo']['hasNextPage']
64-
end_cursor = res['pageInfo']['endCursor']
65-
66-
assert total_count == len(data_row_ids)
67-
return data_row_ids
52+
return PaginatedCollection(
53+
client=self.client,
54+
query=query_str,
55+
params={'id': self.uid},
56+
dereferencing=['getDataRowIdsBySavedQuery', 'nodes'],
57+
obj_class=lambda _, data_row_id: data_row_id,
58+
cursor_path=['getDataRowIdsBySavedQuery', 'pageInfo', 'endCursor'])

0 commit comments

Comments
 (0)