Skip to content

Commit e449339

Browse files
committed
fix: get_datasets_user_shared fails when many circles/collections exist
1 parent c87d7de commit e449339

2 files changed

Lines changed: 31 additions & 9 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
0.17.4
22
- fix: correctly handle dataset IDs and names in `DBExtract`
3+
- fix: `get_datasets_user_shared` failed when many circles/collections exist
34
- ref: decorate PyQtSlots
45
0.17.3
56
- fix: drag'n'drop to DCscope broken since 0.17.0 (#88)

dcoraid/dbmodel/db_api.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from itertools import islice
2+
import sys
13
import urllib.parse
24

35
import numpy as np
@@ -6,6 +8,15 @@
68
from .extract import DBExtract
79

810

11+
if sys.version_info >= (3, 12):
12+
from itertools import batched
13+
else:
14+
def batched(iterable, chunk_size):
15+
iterator = iter(iterable)
16+
while chunk := tuple(islice(iterator, chunk_size)):
17+
yield chunk
18+
19+
920
class APIInterrogator(DBInterrogator):
1021
def __init__(self, api):
1122
self.api = api.copy()
@@ -61,14 +72,24 @@ def get_datasets_user_owned(self):
6172
def get_datasets_user_shared(self):
6273
"""Return datasets shared with the user"""
6374
assert self.mode == "user"
64-
# perform a dataset search with all circles and collections
65-
dbextract = self.search_dataset(
66-
circles=self.get_circles(),
67-
collections=self.get_collections(),
68-
circle_collection_union=True,
69-
filter_queries=[f"-creator_user_id:{self.api.user_id}"],
70-
limit=0,
71-
)
75+
# Perform a dataset search with all circles and collections.
76+
# This search may become too large (414 Request-URI Too Large).
77+
# Limit the search to 20 circles/collections.
78+
dbextract = DBExtract()
79+
80+
for circles_batch in batched(self.get_circles(), 20):
81+
dbextract += self.search_dataset(
82+
circles=list(circles_batch),
83+
filter_queries=[f"-creator_user_id:{self.api.user_id}"],
84+
limit=0,
85+
)
86+
87+
for collections_batch in batched(self.get_collections(), 20):
88+
dbextract += self.search_dataset(
89+
collections=list(collections_batch),
90+
filter_queries=[f"-creator_user_id:{self.api.user_id}"],
91+
limit=0,
92+
)
7293

7394
# all packages the user is a collaborator in
7495
collaborated = self.api.get("package_collaborator_list_for_user",
@@ -114,7 +135,7 @@ def search_dataset(self, query="*:*", filter_queries=None, circles=None,
114135
circle_collection_union: bool
115136
If set to True, make a union of the circle and collection
116137
sets. Otherwise (default), search only for datasets that
117-
are are at least member of one of the circles and one of the
138+
are at least member of one of the circles and one of the
118139
collections.
119140
limit: int
120141
limit number of search results; Set to 0 to get all results

0 commit comments

Comments
 (0)