Skip to content

Commit

Permalink
fix: avoid db query on sync mode all (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Jun 20, 2023
1 parent 84499bc commit 49855d9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/port/controller/package/DownloadPackageVersionTar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AbstractController } from '../AbstractController';
import { FULLNAME_REG_STRING, getScopeAndName } from '../../../common/PackageUtil';
import { NFSAdapter } from '../../../common/adapter/NFSAdapter';
import { PackageManagerService } from '../../../core/service/PackageManagerService';
import { SyncMode } from '../../../common/constants';

@HTTPController()
export class DownloadPackageVersionTarController extends AbstractController {
Expand All @@ -28,11 +29,17 @@ export class DownloadPackageVersionTarController extends AbstractController {
method: HTTPMethodEnum.GET,
})
async download(@Context() ctx: EggContext, @HTTPParam() fullname: string, @HTTPParam() filenameWithVersion: string) {
// try nfs url first, avoid db query
// tgz file storeKey: `/packages/${this.fullname}/${version}/${filename}`
const version = this.getAndCheckVersionFromFilename(ctx, fullname, filenameWithVersion);
const storeKey = `/packages/${fullname}/${version}/${filenameWithVersion}.tgz`;
const downloadUrl = await this.nfsAdapter.getDownloadUrl(storeKey);
if (this.config.cnpmcore.syncMode === SyncMode.all && downloadUrl) {
// try nfs url first, avoid db query
this.packageManagerService.plusPackageVersionCounter(fullname, version);
ctx.redirect(downloadUrl);
return;
}

// check package version in database
const pkg = await this.getPackageEntityByFullname(fullname);
const packageVersion = await this.getPackageVersionEntity(pkg, version);
Expand Down

0 comments on commit 49855d9

Please sign in to comment.