From ef251bee801842faf8c00de20b02e227074a8d0e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Fri, 29 Jan 2021 14:25:43 +0100 Subject: [PATCH] docs.reindex command improved, more responsive UI while reindexing --- .../UI/Spaces/Design-Space/Workspace.js | 34 ++-- .../UI/Spaces/Docs-Space/CommandInterface.js | 6 +- .../UI/Spaces/Docs-Space/SearchEngine.js | 174 +++++++++++------- 3 files changed, 133 insertions(+), 81 deletions(-) diff --git a/Projects/Superalgos/UI/Spaces/Design-Space/Workspace.js b/Projects/Superalgos/UI/Spaces/Design-Space/Workspace.js index 50527b2d0..b86c5b947 100644 --- a/Projects/Superalgos/UI/Spaces/Design-Space/Workspace.js +++ b/Projects/Superalgos/UI/Spaces/Design-Space/Workspace.js @@ -108,17 +108,19 @@ function newWorkspace() { UI.projects.superalgos.utilities.statusBar.changeStatus("Setting up Docs Search Engine...") setTimeout(theEnd, 100) function theEnd() { - UI.projects.superalgos.spaces.docsSpace.searchEngine.setUpSearchEngine() + UI.projects.superalgos.spaces.docsSpace.searchEngine.setUpSearchEngine(onIndexingFinished) - setupEventsServerClients() - runTasksAndSessions() - thisObject.enabled = true - UI.projects.superalgos.spaces.cockpitSpace.initializePosition() - CAN_SPACES_DRAW = true + function onIndexingFinished() { + setupEventsServerClients() + runTasksAndSessions() + thisObject.enabled = true + UI.projects.superalgos.spaces.cockpitSpace.initializePosition() + CAN_SPACES_DRAW = true - thisObject.isInitialized = true - savingWorkspaceIntervalId = setInterval(saveWorkspace, 60000) - UI.projects.superalgos.utilities.statusBar.changeStatus("Displaying the UI...") + thisObject.isInitialized = true + savingWorkspaceIntervalId = setInterval(saveWorkspace, 60000) + UI.projects.superalgos.utilities.statusBar.changeStatus("Displaying the UI...") + } } } } catch (err) { @@ -368,12 +370,14 @@ function newWorkspace() { workingAtTask = 0 function takeAction() { - UI.projects.superalgos.spaces.docsSpace.reset() - UI.projects.superalgos.spaces.docsSpace.searchEngine.setUpSearchEngine() // The docs needs to index the loaded workspace. - UI.projects.superalgos.spaces.floatingSpace.inMapMode = false - thisObject.isInitialized = true - saveWorkspace() - runTasksAndSessions() + UI.projects.superalgos.spaces.docsSpace.reset() + UI.projects.superalgos.spaces.docsSpace.searchEngine.setUpSearchEngine(onIndexingFinished) // The docs needs to index the loaded workspace. + function onIndexingFinished() { + UI.projects.superalgos.spaces.floatingSpace.inMapMode = false + thisObject.isInitialized = true + saveWorkspace() + runTasksAndSessions() + } } break } diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js b/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js index 864371019..d039c7372 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/CommandInterface.js @@ -468,9 +468,11 @@ function newSuperalgosDocsCommmandInterface() { setTimeout(startReindexingProcess, 100) function startReindexingProcess() { - UI.projects.superalgos.spaces.docsSpace.searchEngine.setUpSearchEngine() + UI.projects.superalgos.spaces.docsSpace.searchEngine.setUpSearchEngine(onFinish) - UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Message - Reindexing Done') + function onFinish() { + UI.projects.superalgos.spaces.docsSpace.navigateTo('Superalgos', 'Topic', 'Docs Message - Reindexing Done') + } } } diff --git a/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js index 8b6c3659d..101ce7823 100644 --- a/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js +++ b/Projects/Superalgos/UI/Spaces/Docs-Space/SearchEngine.js @@ -16,7 +16,10 @@ function newSuperalgosDocsSearchEngine() { thisObject.docsIndex = undefined } - function setUpSearchEngine() { + function setUpSearchEngine(callbackFunction) { + + let totalAsyncCallsMade = 0 + let totalAsyncCallsFinished = 0 setUpWorkspaceSchemas() thisObject.docsIndex = [] @@ -26,82 +29,125 @@ function newSuperalgosDocsSearchEngine() { let documentIndex - /* Search in Nodes */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema[i], - category: 'Node', - project: project + totalAsyncCallsMade++ + setTimeout(searchInNodes, 0) + totalAsyncCallsMade++ + setTimeout(searchInConcepts, 0) + totalAsyncCallsMade++ + setTimeout(searchInNTopics, 0) + totalAsyncCallsMade++ + setTimeout(searchInTutorials, 0) + totalAsyncCallsMade++ + setTimeout(searchInReviews, 0) + totalAsyncCallsMade++ + setTimeout(searchInBooks, 0) + totalAsyncCallsMade++ + setTimeout(searchInWorkspaces, 0) + + function searchInNodes() { + /* Search in Nodes */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema[i], + category: 'Node', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) } - indexDocument(documentIndex) - thisObject.docsIndex.push(documentIndex) + asyncCallFinished() } - /* Search in Concepts */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema[i], - category: 'Concept', - project: project + function searchInConcepts() { + /* Search in Concepts */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema[i], + category: 'Concept', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) } - indexDocument(documentIndex) - thisObject.docsIndex.push(documentIndex) + asyncCallFinished() } - /* Search in Topics */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema[i], - category: 'Topic', - project: project + function searchInNTopics() { + /* Search in Topics */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema[i], + category: 'Topic', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) } - indexDocument(documentIndex) - thisObject.docsIndex.push(documentIndex) + asyncCallFinished() } - /* Search in Tutorials */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsTutorialSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsTutorialSchema[i], - category: 'Tutorial', - project: project + function searchInTutorials() { + /* Search in Tutorials */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsTutorialSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsTutorialSchema[i], + category: 'Tutorial', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) } - indexDocument(documentIndex) - thisObject.docsIndex.push(documentIndex) + asyncCallFinished() } - /* Search in Reviews */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsReviewSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsReviewSchema[i], - category: 'Review', - project: project + function searchInReviews() { + /* Search in Reviews */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsReviewSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsReviewSchema[i], + category: 'Review', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) } - indexDocument(documentIndex) - thisObject.docsIndex.push(documentIndex) + asyncCallFinished() } - /* Search in Books */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsBookSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsBookSchema[i], - category: 'Book', - project: project + function searchInBooks() { + /* Search in Books */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.docsBookSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.docsBookSchema[i], + category: 'Book', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) } - indexDocument(documentIndex) - thisObject.docsIndex.push(documentIndex) + asyncCallFinished() } - /* Search in Workspace */ - for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.workspaceSchema.length; i++) { - documentIndex = { - phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. - docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.workspaceSchema[i], - category: 'Workspace', - project: project + function searchInWorkspaces() { + /* Search in Workspace */ + for (let i = 0; i < SCHEMAS_BY_PROJECT.get(project).array.workspaceSchema.length; i++) { + documentIndex = { + phraseCount: {}, // here we have an object with properties matching it paragraph style, and each property is a map of phrases and their total count. + docsSchemaDocument: SCHEMAS_BY_PROJECT.get(project).array.workspaceSchema[i], + category: 'Workspace', + project: project + } + indexDocument(documentIndex) + thisObject.docsIndex.push(documentIndex) + } + asyncCallFinished() + } + + function asyncCallFinished() { + totalAsyncCallsFinished++ + if (totalAsyncCallsMade === totalAsyncCallsFinished) { + callbackFunction() } - indexDocument(documentIndex) - thisObject.docsIndex.push(documentIndex) } }