Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1 search does not work with pagination #3545

Open
dre2901 opened this issue Dec 28, 2022 · 4 comments
Open

v1 search does not work with pagination #3545

dre2901 opened this issue Dec 28, 2022 · 4 comments

Comments

@dre2901
Copy link

dre2901 commented Dec 28, 2022

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch verdaccio@5.18.0 for the project I'm working on.

The problem is in 5.x/src/api/endpoint/api/v1/search.ts (I checked and the same logical issue exists also in master 6.x branch master/packages/api/src/v1/search.ts).

Basically, search returns always total equal or less than size query param.

For example, direct search of @babel packages on npmjs (https://registry.npmjs.org/-/v1/search?text=@babel&size=20&from=0) returns total of 192 and I can do pagination by using size and from params.
Same call via verdaccio returns always total of 20 (equal to size) and pagination is not possible at all.

Here is the diff that solved my problem:

diff --git a/node_modules/verdaccio/build/api/endpoint/api/v1/search.js b/node_modules/verdaccio/build/api/endpoint/api/v1/search.js
index 27b03a0..8b1939e 100644
--- a/node_modules/verdaccio/build/api/endpoint/api/v1/search.js
+++ b/node_modules/verdaccio/build/api/endpoint/api/v1/search.js
@@ -106,11 +106,12 @@ async function sendResponse(resultBuf, resultStream, auth, req, from, size) {
   const checkAccessPromises = await Promise.all(removeDuplicates(resultsCollection).map(pkgItem => {
     return checkAccess(pkgItem, auth, req.remote_user);
   }));
-  const final = checkAccessPromises.filter(i => !_lodash.default.isNull(i)).slice(from, size);
+  const totalAllowed = checkAccessPromises.filter(i => !_lodash.default.isNull(i));
+  const final = totalAllowed.slice(from, from + size);
   _logger.logger.debug(`search results ${final === null || final === void 0 ? void 0 : final.length}`);
   const response = {
     objects: final,
-    total: final.length,
+    total: totalAllowed.length,
     time: new Date().toUTCString()
   };
   _logger.logger.debug(`total response ${final.length}`);

This issue body was partially generated by patch-package.

@juanpicado
Copy link
Member

Thanks @dre2901 for the details, I haven't checked this but I'm interested to dive more into this topic.

@juanpicado
Copy link
Member

I applied the patch but seems not that simple, the total amount comes from npmjs but is not pass through to the verdaccio logic, the total returned is always the items from the first page + those local matches. It requires more internal changes.

@maxoyed
Copy link

maxoyed commented Jun 19, 2023

any progress on this?

@juanpicado
Copy link
Member

Nop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants