Browse Source

fix(core): Disable index builder worker thread for sql.js

For some reason it does not work with sql.js - updating the index results in an empty table.
Michael Bromley 6 years ago
parent
commit
a49d1a341b

+ 1 - 1
packages/core/src/plugin/default-search-plugin/indexer/index-builder.ts

@@ -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);
     }

+ 6 - 2
packages/core/src/plugin/default-search-plugin/indexer/search-index.service.ts

@@ -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';
@@ -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);
@@ -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,
@@ -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 => {