summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/stores/actions.js
diff options
context:
space:
mode:
authorPaul Slaughter <pslaughter@gitlab.com>2019-03-07 09:22:05 +0000
committerPhil Hughes <me@iamphill.com>2019-03-07 09:22:05 +0000
commitc49d4a4985c806aa62dcd4899013143484b5d3c6 (patch)
treead43a15e05364b9e24c3eceb9de37b8e37afb51a /app/assets/javascripts/ide/stores/actions.js
parent80fea82f3ab6afd486884020710eb01c06b048d9 (diff)
downloadgitlab-ce-c49d4a4985c806aa62dcd4899013143484b5d3c6.tar.gz
Improve files_decorator performance
**How?** Previously the files_decorator inserted parent folders inefficiently. It started at the first part and ensured each was inserted. Since the file entries are given to use in alphabetical order, we can start at the last part of the blob's parents. If this exists, we can short circuit and be done inserting parents. **What else?** - Improve performance of decorateData. The object spread operator is not needed because the object is brand new.
Diffstat (limited to 'app/assets/javascripts/ide/stores/actions.js')
-rw-r--r--app/assets/javascripts/ide/stores/actions.js48
1 files changed, 21 insertions, 27 deletions
diff --git a/app/assets/javascripts/ide/stores/actions.js b/app/assets/javascripts/ide/stores/actions.js
index 95d91e08757..7b660bda081 100644
--- a/app/assets/javascripts/ide/stores/actions.js
+++ b/app/assets/javascripts/ide/stores/actions.js
@@ -3,7 +3,7 @@ import Vue from 'vue';
import { visitUrl } from '~/lib/utils/url_utility';
import flash from '~/flash';
import * as types from './mutation_types';
-import FilesDecoratorWorker from './workers/files_decorator_worker';
+import { decorateFiles } from '../lib/files';
import { stageKeys } from '../constants';
export const redirectToUrl = (_, url) => visitUrl(url);
@@ -56,7 +56,6 @@ export const createTempEntry = (
{ name, type, content = '', base64 = false },
) =>
new Promise(resolve => {
- const worker = new FilesDecoratorWorker();
const fullName = name.slice(-1) !== '/' && type === 'tree' ? `${name}/` : name;
if (state.entries[name]) {
@@ -74,31 +73,7 @@ export const createTempEntry = (
return null;
}
- worker.addEventListener('message', ({ data }) => {
- const { file, parentPath } = data;
-
- worker.terminate();
-
- commit(types.CREATE_TMP_ENTRY, {
- data,
- projectId: state.currentProjectId,
- branchId: state.currentBranchId,
- });
-
- if (type === 'blob') {
- commit(types.TOGGLE_FILE_OPEN, file.path);
- commit(types.ADD_FILE_TO_CHANGED, file.path);
- dispatch('setFileActive', file.path);
- }
-
- if (parentPath && !state.entries[parentPath].opened) {
- commit(types.TOGGLE_TREE_OPEN, parentPath);
- }
-
- resolve(file);
- });
-
- worker.postMessage({
+ const data = decorateFiles({
data: [fullName],
projectId: state.currentProjectId,
branchId: state.currentBranchId,
@@ -107,6 +82,25 @@ export const createTempEntry = (
base64,
content,
});
+ const { file, parentPath } = data;
+
+ commit(types.CREATE_TMP_ENTRY, {
+ data,
+ projectId: state.currentProjectId,
+ branchId: state.currentBranchId,
+ });
+
+ if (type === 'blob') {
+ commit(types.TOGGLE_FILE_OPEN, file.path);
+ commit(types.ADD_FILE_TO_CHANGED, file.path);
+ dispatch('setFileActive', file.path);
+ }
+
+ if (parentPath && !state.entries[parentPath].opened) {
+ commit(types.TOGGLE_TREE_OPEN, parentPath);
+ }
+
+ resolve(file);
return null;
});