0
Fork 0
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:
Juan Picado @jotadeveloper 2018-11-22 13:39:39 +01:00 committed by GitHub
parent 712db31a43
commit 2362310aba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 5 deletions

View file

@ -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) { route.get('/-/package/:package/dist-tags', can('access'), function(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer) {
storage.getPackage({ storage.getPackage({
name: req.params.package, name: req.params.package,
uplinksLook: true,
req, req,
callback: function(err, info) { callback: function(err, info) {
if (err) { if (err) {

View file

@ -45,6 +45,7 @@ export default function(route: Router, auth: IAuth, storage: IStorageHandler, co
storage.getPackage({ storage.getPackage({
name: req.params.package, name: req.params.package,
uplinksLook: true,
req, req,
callback: getPackageMetaCallback, callback: getPackageMetaCallback,
}); });

View file

@ -60,6 +60,7 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth)
storage.getPackage({ storage.getPackage({
name: packageName, name: packageName,
uplinksLook: true,
req, req,
callback: function(err, info) { callback: function(err, info) {
if (err) { if (err) {
@ -77,6 +78,7 @@ function addPackageWebApi(route: Router, storage: IStorageHandler, auth: IAuth)
storage.getPackage({ storage.getPackage({
name: packageName, name: packageName,
uplinksLook: true,
keepUpLinkData: true, keepUpLinkData: true,
req, req,
callback: function(err: Error, info: $SidebarPackage) { callback: function(err: Error, info: $SidebarPackage) {

View file

@ -17,6 +17,7 @@ function addSearchWebApi(route: Router, storage: IStorageHandler, auth: IAuth) {
const getPackageInfo = function(i) { const getPackageInfo = function(i) {
storage.getPackage({ storage.getPackage({
name: results[i].ref, name: results[i].ref,
uplinksLook: false,
callback: (err, entry) => { callback: (err, entry) => {
if (!err && entry) { if (!err && entry) {
auth.allow_access(entry.name, req.remote_user, function(err, allowed) { auth.allow_access(entry.name, req.remote_user, function(err, allowed) {

View file

@ -16,7 +16,7 @@ import { checkPackageLocal, publishPackage, checkPackageRemote, cleanUpLinksRef,
import { setupUpLinks, updateVersionsHiddenUpLink } from './uplink-util'; import { setupUpLinks, updateVersionsHiddenUpLink } from './uplink-util';
import { mergeVersions } from './metadata-utils'; import { mergeVersions } from './metadata-utils';
import { ErrorCode, normalizeDistTags, validateMetadata, isObject } from './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 { Versions, Package, Config, MergeTags, Version, DistFile, Callback, Logger } from '@verdaccio/types';
import type { IReadTarball, IUploadTarball } from '@verdaccio/streams'; import type { IReadTarball, IUploadTarball } from '@verdaccio/streams';
import { hasProxyTo } from './config-utils'; 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 {boolean} options.keepUpLinkData keep up link info in package meta, last update, etc.
* @property {function} options.callback Callback for receive data * @property {function} options.callback Callback for receive data
*/ */
getPackage(options: any) { getPackage(options: IGetPackageOptions) {
this.localStorage.getPackageMetadata(options.name, (err, data) => { this.localStorage.getPackageMetadata(options.name, (err, data) => {
if (err && (!err.status || err.status >= HTTP_STATUS.INTERNAL_ERROR)) { if (err && (!err.status || err.status >= HTTP_STATUS.INTERNAL_ERROR)) {
// report internal errors right away // report internal errors right away
return options.callback(err); 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) { if (err) {
return options.callback(err); return options.callback(err);
} }
@ -401,10 +405,11 @@ class Storage implements IStorageHandler {
if package is available locally, it MUST be provided in pkginfo if package is available locally, it MUST be provided in pkginfo
returns callback(err, result, uplink_errors) 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; let exists = true;
const self = this; const self = this;
const upLinks = []; const upLinks = [];
const hasToLookIntoUplinks = _.isNil(options.uplinksLook) || options.uplinksLook;
if (!packageInfo || packageInfo === null) { if (!packageInfo || packageInfo === null) {
exists = false; exists = false;
@ -412,7 +417,7 @@ class Storage implements IStorageHandler {
} }
for (let uplink in this.uplinks) { 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]); upLinks.push(this.uplinks[uplink]);
} }
} }

View file

@ -135,6 +135,19 @@ export interface IStorage extends IBasicStorage {
logger: Logger; 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 { export interface IStorageHandler extends IStorageManager {
localStorage: IStorage; localStorage: IStorage;
uplinks: ProxyList; uplinks: ProxyList;