Skip to content

Commit f98048c

Browse files
committed
Merge branch 'mr/cardao/maven-pagination' into 'master'
Fix maven request See merge request it/e3-core!116
2 parents dc06443 + 53a7bdc commit f98048c

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/e3/maven.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,40 @@ def fetch_project_links(
9898
"""
9999
if name not in self.cache:
100100
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.
101132
request = requests.get(
102133
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",
104135
headers=headers,
105136
)
106137
request.raise_for_status()

0 commit comments

Comments
 (0)