-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Expose pending search index updates operations in Admin API
Relates to #1137
- Loading branch information
1 parent
95d4445
commit 53a1943
Showing
19 changed files
with
156 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/core/src/api/schema/admin-api/product-search.api.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
type Query { | ||
search(input: SearchInput!): SearchResponse! | ||
pendingSearchIndexUpdates: Int! | ||
} | ||
|
||
type Mutation { | ||
reindex: Job! | ||
runPendingSearchIndexUpdates: Success! | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const PLUGIN_INIT_OPTIONS = Symbol('PLUGIN_INIT_OPTIONS'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
...lt-search-plugin/collection-job-buffer.ts → ...earch-job-buffer/collection-job-buffer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
...efault-search-plugin/search-job-buffer.ts → ...rch-job-buffer/search-index-job-buffer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ages/core/src/plugin/default-search-plugin/search-job-buffer/search-job-buffer.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Inject, Injectable, OnApplicationBootstrap } from '@nestjs/common'; | ||
import { forkJoin } from 'rxjs'; | ||
|
||
import { ConfigService } from '../../../config/config.service'; | ||
import { isInspectableJobQueueStrategy } from '../../../config/job-queue/inspectable-job-queue-strategy'; | ||
import { JobQueueService } from '../../../job-queue/job-queue.service'; | ||
import { SubscribableJob } from '../../../job-queue/subscribable-job'; | ||
import { PLUGIN_INIT_OPTIONS } from '../constants'; | ||
import { DefaultSearchPluginInitOptions } from '../types'; | ||
|
||
import { CollectionJobBuffer } from './collection-job-buffer'; | ||
import { SearchIndexJobBuffer } from './search-index-job-buffer'; | ||
|
||
@Injectable() | ||
export class SearchJobBufferService implements OnApplicationBootstrap { | ||
readonly searchIndexJobBuffer = new SearchIndexJobBuffer(); | ||
readonly collectionJobBuffer = new CollectionJobBuffer(); | ||
|
||
constructor( | ||
private jobQueueService: JobQueueService, | ||
private configService: ConfigService, | ||
@Inject(PLUGIN_INIT_OPTIONS) private options: DefaultSearchPluginInitOptions, | ||
) {} | ||
|
||
onApplicationBootstrap(): any { | ||
if (this.options.bufferUpdates === true) { | ||
this.jobQueueService.addBuffer(this.searchIndexJobBuffer); | ||
this.jobQueueService.addBuffer(this.collectionJobBuffer); | ||
} | ||
} | ||
|
||
async getPendingSearchUpdates(): Promise<number> { | ||
if (!this.options.bufferUpdates) { | ||
return 0; | ||
} | ||
const bufferSizes = await this.jobQueueService.bufferSize( | ||
this.searchIndexJobBuffer, | ||
this.collectionJobBuffer, | ||
); | ||
return ( | ||
(bufferSizes[this.searchIndexJobBuffer.id] ?? 0) + (bufferSizes[this.collectionJobBuffer.id] ?? 0) | ||
); | ||
} | ||
|
||
async runPendingSearchUpdates(): Promise<void> { | ||
if (!this.options.bufferUpdates) { | ||
return; | ||
} | ||
const { jobQueueStrategy } = this.configService.jobQueueOptions; | ||
|
||
const collectionFilterJobs = await this.jobQueueService.flush(this.collectionJobBuffer); | ||
if (collectionFilterJobs.length && isInspectableJobQueueStrategy(jobQueueStrategy)) { | ||
const subscribableCollectionJobs = collectionFilterJobs.map( | ||
job => new SubscribableJob(job, jobQueueStrategy), | ||
); | ||
await forkJoin( | ||
...subscribableCollectionJobs.map(sj => | ||
sj.updates({ pollInterval: 500, timeoutMs: 3 * 60 * 1000 }), | ||
), | ||
).toPromise(); | ||
} | ||
await this.jobQueueService.flush(this.searchIndexJobBuffer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.