Skip to content

Commit

Permalink
fix(core): Disable index builder worker thread for sql.js
Browse files Browse the repository at this point in the history
For some reason it does not work with sql.js - updating the index results in an empty table.
  • Loading branch information
michaelbromley committed Jun 6, 2019
1 parent eadbdf6 commit a49d1a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class IndexBuilder {
private async connect(dbConnectionOptions: ConnectionOptions): Promise<ConnectedMessage> {
const {coreEntitiesMap} = await import('../../../entity/entities');
const coreEntities = Object.values(coreEntitiesMap) as Array<Type<any>>;
this.connection = await createConnection({...dbConnectionOptions, entities: [SearchIndexItem, ...coreEntities]});
this.connection = await createConnection({...dbConnectionOptions, entities: [SearchIndexItem, ...coreEntities], name: 'index-builder' });
this.indexQueryBuilder = getSearchIndexQueryBuilder(this.connection);
return new ConnectedMessage(this.connection.isConnected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import {
SaveVariantsMessage,
VariantsSavedMessage,
} from './ipc';
// This import is needed to ensure that the worker script gets compiled
// and emitted during build.
import './search-index-worker';

export type IncomingMessage = ConnectedMessage | ReturnRawBatchMessage | VariantsSavedMessage | CompletedMessage;
const loggerCtx = 'DefaultSearchPlugin';
Expand All @@ -58,7 +61,7 @@ export class SearchIndexService {
* Creates the search index worker process and has it connect to the database.
*/
async connect() {
if (this.options.runInForkedProcess) {
if (this.options.runInForkedProcess && this.configService.dbConnectionOptions.type !== 'sqljs') {
try {
const workerProcess = this.getChildProcess(path.join(__dirname, 'search-index-worker.ts'));
Logger.verbose(`IndexBuilder running as forked process`, loggerCtx);
Expand Down Expand Up @@ -122,6 +125,7 @@ export class SearchIndexService {

const variants = await this.getBatch(this.workerProcess, i);
const hydratedVariants = this.hydrateVariants(ctx, variants);
Logger.verbose(`variants count: ${variants.length}`);

ipcChannel.send(new SaveVariantsMessage({
variants: hydratedVariants,
Expand Down Expand Up @@ -275,7 +279,7 @@ export class SearchIndexService {

private establishConnection(child: ChildProcess): Promise<boolean> {
const connectionOptions = pick(this.configService.dbConnectionOptions as any,
['type', 'name', 'database', 'host', 'port', 'username', 'password']);
['type', 'name', 'database', 'host', 'port', 'username', 'password', 'location', 'autoSave']);
return new Promise(resolve => {
const ipcChannel = new IpcChannel(child);
ipcChannel.subscribe(MessageType.CONNECTED, message => {
Expand Down

0 comments on commit a49d1a3

Please sign in to comment.