diff --git a/app/core/event/SyncESPackage.ts b/app/core/event/SyncESPackage.ts index 80df5f1b..dd83175d 100644 --- a/app/core/event/SyncESPackage.ts +++ b/app/core/event/SyncESPackage.ts @@ -12,6 +12,8 @@ import { PACKAGE_MAINTAINER_CHANGED, PACKAGE_MAINTAINER_REMOVED, PACKAGE_META_CHANGED, + PACKAGE_BLOCKED, + PACKAGE_UNBLOCKED, } from './index'; import { PackageSearchService } from '../service/PackageSearchService'; @@ -30,6 +32,7 @@ class SyncESPackage { } @Event(PACKAGE_UNPUBLISHED) +@Event(PACKAGE_BLOCKED) export class PackageUnpublished extends SyncESPackage { async handle(fullname: string) { if (!this.config.cnpmcore.enableElasticsearch) return; @@ -38,56 +41,15 @@ export class PackageUnpublished extends SyncESPackage { } @Event(PACKAGE_VERSION_ADDED) -export class PackageVersionAdded extends SyncESPackage { - async handle(fullname: string) { - await this.syncPackage(fullname); - } -} - +@Event(PACKAGE_META_CHANGED) @Event(PACKAGE_VERSION_REMOVED) -export class PackageVersionRemoved extends SyncESPackage { - async handle(fullname: string) { - await this.syncPackage(fullname); - } -} - @Event(PACKAGE_TAG_ADDED) -export class PackageTagAdded extends SyncESPackage { - async handle(fullname: string) { - await this.syncPackage(fullname); - } -} - @Event(PACKAGE_TAG_CHANGED) -export class PackageTagChanged extends SyncESPackage { - async handle(fullname: string) { - await this.syncPackage(fullname); - } -} - @Event(PACKAGE_TAG_REMOVED) -export class PackageTagRemoved extends SyncESPackage { - async handle(fullname: string) { - await this.syncPackage(fullname); - } -} - @Event(PACKAGE_MAINTAINER_CHANGED) -export class PackageMaintainerChanged extends SyncESPackage { - async handle(fullname: string) { - await this.syncPackage(fullname); - } -} - @Event(PACKAGE_MAINTAINER_REMOVED) -export class PackageMaintainerRemoved extends SyncESPackage { - async handle(fullname: string) { - await this.syncPackage(fullname); - } -} - -@Event(PACKAGE_META_CHANGED) -export class PackageMetaChanged extends SyncESPackage { +@Event(PACKAGE_UNBLOCKED) +export class PackageVersionAdded extends SyncESPackage { async handle(fullname: string) { await this.syncPackage(fullname); } diff --git a/app/core/service/PackageSearchService.ts b/app/core/service/PackageSearchService.ts index 04000d96..4ef75858 100644 --- a/app/core/service/PackageSearchService.ts +++ b/app/core/service/PackageSearchService.ts @@ -8,6 +8,7 @@ import { PackageManagerService } from './PackageManagerService'; import { SearchManifestType, SearchMappingType, SearchRepository } from '../../repository/SearchRepository'; import { PackageVersionDownloadRepository } from '../../repository/PackageVersionDownloadRepository'; import { PackageRepository } from '../../repository/PackageRepository'; +import { PackageVersionBlockRepository } from '../../repository/PackageVersionBlockRepository'; @SingletonProto({ @@ -22,6 +23,8 @@ export class PackageSearchService extends AbstractService { private packageVersionDownloadRepository: PackageVersionDownloadRepository; @Inject() protected packageRepository: PackageRepository; + @Inject() + protected packageVersionBlockRepository: PackageVersionBlockRepository; async syncPackage(fullname: string, isSync = true) { const [ scope, name ] = getScopeAndName(fullname); @@ -38,6 +41,13 @@ export class PackageSearchService extends AbstractService { return; } + const block = await this.packageVersionBlockRepository.findPackageBlock(pkg.packageId); + if (block) { + this.logger.warn('[PackageSearchService.syncPackage] package:%s is blocked, try to remove es', fullname); + await this.removePackage(fullname); + return; + } + // get last year download data const startDate = dayjs().subtract(1, 'year'); const endDate = dayjs();