File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -98,9 +98,40 @@ def fetch_project_links(
98
98
"""
99
99
if name not in self .cache :
100
100
logger .debug (f"fetch { name } links from { self .url } " )
101
+ # First get the number of elements to retrieve using rows=0.
102
+ # This will return a JSON like:
103
+ # {
104
+ # "reponseHeader": { ... },
105
+ # "reponse" : {
106
+ # "numFound": X,
107
+ # ...
108
+ # }
109
+ # }
110
+ #
111
+ # The numFound is the number of rows to ask. Currently, we don't find any
112
+ # case where this number is too big for making only one query.
113
+ tmp_request = requests .get (
114
+ f"{ self .url } ?q="
115
+ f"g:%22{ group } %22+AND+a:%22{ name } %22&core=gav&rows=0&wt=json" ,
116
+ headers = headers ,
117
+ )
118
+ tmp_request .raise_for_status ()
119
+
120
+ tmp = tmp_request .json ()
121
+
122
+ if "response" not in tmp or "numFound" not in tmp ["response" ]:
123
+ raise KeyError (
124
+ "Cannot determine the number of rows to request: "
125
+ "'response:numFound' key not found."
126
+ )
127
+
128
+ rows = tmp ["response" ]["numFound" ]
129
+
130
+ # Now, we have our numbers of rows, so lets make the same request, but with
131
+ # the right parameters.
101
132
request = requests .get (
102
133
f"{ self .url } ?q="
103
- f"g:%22{ group } %22+AND+a:%22{ name } %22&core=gav&rows=20 &wt=json" ,
134
+ f"g:%22{ group } %22+AND+a:%22{ name } %22&core=gav&rows={ rows } &wt=json" ,
104
135
headers = headers ,
105
136
)
106
137
request .raise_for_status ()
You can’t perform that action at this time.
0 commit comments