mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-30 22:34:10 -05:00
feat: stop hit proxies on search web UI (#1126)
Since we look for metadata on sidebar does not make sense to hit the proxies on search, this is the first step to help with other tickets to search in the whole proxy data packages, now is limited to private packages. Unit test are not need it here since is an "assumed" behaviour we don't want anymore. This will clearly help to improve performance on UI.
This commit is contained in:
parent
712db31a43
commit
2362310aba
6 changed files with 28 additions and 5 deletions
|
@ -52,6 +52,7 @@ export default function(route: Router, auth: IAuth, storage: IStorageHandler) {
|
|||
route.get('/-/package/:package/dist-tags', can('access'), function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
|
||||
storage.getPackage({
|
||||
name: req.params.package,
|
||||
uplinksLook: true,
|
||||
req,
|
||||
callback: function(err, info) {
|
||||
if (err) {
|
||||
|
|
|
@ -45,6 +45,7 @@ export default function(route: Router, auth: IAuth, storage: IStorageHandler, co
|
|||
|
||||
storage.getPackage({
|
||||
name: req.params.package,
|
||||
uplinksLook: true,
|
||||
req,
|
||||
callback: getPackageMetaCallback,
|
||||
});
|
||||
|
|
|
@ -60,6 +60,7 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth)
|
|||
|
||||
storage.getPackage({
|
||||
name: packageName,
|
||||
uplinksLook: true,
|
||||
req,
|
||||
callback: function(err, info) {
|
||||
if (err) {
|
||||
|
@ -77,6 +78,7 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth)
|
|||
|
||||
storage.getPackage({
|
||||
name: packageName,
|
||||
uplinksLook: true,
|
||||
keepUpLinkData: true,
|
||||
req,
|
||||
callback: function(err: Error, info: $SidebarPackage) {
|
||||
|
|
|
@ -17,6 +17,7 @@ function addSearchWebApi(route: Router, storage: IStorageHandler, auth: IAuth) {
|
|||
const getPackageInfo = function(i) {
|
||||
storage.getPackage({
|
||||
name: results[i].ref,
|
||||
uplinksLook: false,
|
||||
callback: (err, entry) => {
|
||||
if (!err && entry) {
|
||||
auth.allow_access(entry.name, req.remote_user, function(err, allowed) {
|
||||
|
|
|
@ -16,7 +16,7 @@ import { checkPackageLocal, publishPackage, checkPackageRemote, cleanUpLinksRef,
|
|||
import { setupUpLinks, updateVersionsHiddenUpLink } from './uplink-util';
|
||||
import { mergeVersions } from './metadata-utils';
|
||||
import { ErrorCode, normalizeDistTags, validateMetadata, isObject } from './utils';
|
||||
import type { IStorage, IProxy, IStorageHandler, ProxyList, StringValue } from '../../types';
|
||||
import type { IStorage, IProxy, IStorageHandler, ProxyList, StringValue, IGetPackageOptions, ISyncUplinks } from '../../types';
|
||||
import type { Versions, Package, Config, MergeTags, Version, DistFile, Callback, Logger } from '@verdaccio/types';
|
||||
import type { IReadTarball, IUploadTarball } from '@verdaccio/streams';
|
||||
import { hasProxyTo } from './config-utils';
|
||||
|
@ -263,14 +263,18 @@ class Storage implements IStorageHandler {
|
|||
* @property {boolean} options.keepUpLinkData keep up link info in package meta, last update, etc.
|
||||
* @property {function} options.callback Callback for receive data
|
||||
*/
|
||||
getPackage(options: any) {
|
||||
getPackage(options: IGetPackageOptions) {
|
||||
this.localStorage.getPackageMetadata(options.name, (err, data) => {
|
||||
if (err && (!err.status || err.status >= HTTP_STATUS.INTERNAL_ERROR)) {
|
||||
// report internal errors right away
|
||||
return options.callback(err);
|
||||
}
|
||||
|
||||
this._syncUplinksMetadata(options.name, data, { req: options.req }, function getPackageSynUpLinksCallback(err, result: Package, uplinkErrors) {
|
||||
this._syncUplinksMetadata(options.name, data, { req: options.req, uplinksLook: options.uplinksLook }, function getPackageSynUpLinksCallback(
|
||||
err,
|
||||
result: Package,
|
||||
uplinkErrors
|
||||
) {
|
||||
if (err) {
|
||||
return options.callback(err);
|
||||
}
|
||||
|
@ -401,10 +405,11 @@ class Storage implements IStorageHandler {
|
|||
if package is available locally, it MUST be provided in pkginfo
|
||||
returns callback(err, result, uplink_errors)
|
||||
*/
|
||||
_syncUplinksMetadata(name: string, packageInfo: Package, options: any, callback: Callback): void {
|
||||
_syncUplinksMetadata(name: string, packageInfo: Package, options: ISyncUplinks, callback: Callback): void {
|
||||
let exists = true;
|
||||
const self = this;
|
||||
const upLinks = [];
|
||||
const hasToLookIntoUplinks = _.isNil(options.uplinksLook) || options.uplinksLook;
|
||||
|
||||
if (!packageInfo || packageInfo === null) {
|
||||
exists = false;
|
||||
|
@ -412,7 +417,7 @@ class Storage implements IStorageHandler {
|
|||
}
|
||||
|
||||
for (let uplink in this.uplinks) {
|
||||
if (hasProxyTo(name, uplink, this.config.packages)) {
|
||||
if (hasProxyTo(name, uplink, this.config.packages) && hasToLookIntoUplinks) {
|
||||
upLinks.push(this.uplinks[uplink]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,6 +135,19 @@ export interface IStorage extends IBasicStorage {
|
|||
logger: Logger;
|
||||
}
|
||||
|
||||
export type IGetPackageOptions = {
|
||||
callback: Callback;
|
||||
name: string;
|
||||
keepUpLinkData: boolean;
|
||||
uplinksLook: boolean;
|
||||
req: any;
|
||||
}
|
||||
|
||||
export type ISyncUplinks = {
|
||||
uplinksLook?: boolean;
|
||||
etag?: string;
|
||||
}
|
||||
|
||||
export interface IStorageHandler extends IStorageManager {
|
||||
localStorage: IStorage;
|
||||
uplinks: ProxyList;
|
||||
|
|
Loading…
Reference in a new issue