Skip to content

TagSpaces is an offline, open source, document manager with tagging support

removing search index from redux

Ilian Sapundshieva8a0e5446248
diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.ts
index e66fcd682..63801fda2 100644
--- a/app/reducers/location-index.ts
+++ b/app/reducers/location-index.ts
@@ -26,12 +26,12 @@ import {
// getThumbFileLocationForFile
} from '../utils/paths';
import Search, { SearchQuery } from '../services/search';
-
import { actions as AppActions } from './app';
import AppConfig from '../config';
import i18n from '../services/i18n';
// import PlatformIO from '../services/platform-io';
import { Tag } from './taglibrary';
+import SearchIndex from '../services/search-index';
export const types = {
INDEX_DIRECTORY: 'INDEX_DIRECTORY',
@@ -49,7 +49,6 @@ export const types = {
};
export const initialState = {
- currentDirectoryIndex: [],
isIndexing: false
};
@@ -58,14 +57,14 @@ export default (state: any = initialState, action: any) => {
case types.INDEX_DIRECTORY_START: {
return {
...state,
- currentDirectoryIndex: [],
isIndexing: true
};
}
case types.INDEX_DIRECTORY_CLEAR: {
+ // SearchIndex.length = 0;
+ SearchIndex.splice(0, SearchIndex.length);
return {
...state,
- currentDirectoryIndex: [],
isIndexing: false
};
}
@@ -76,62 +75,53 @@ export default (state: any = initialState, action: any) => {
case types.INDEX_DIRECTORY_SUCCESS: {
return {
...state,
- currentDirectoryIndex: action.directoryIndex,
isIndexing: false
};
}
case types.INDEX_DIRECTORY_FAILURE: {
+ // SearchIndex.length = 0;
return {
...state,
lastError: action.error,
- currentDirectoryIndex: [],
isIndexing: false
};
}
case types.REFLECT_DELETE_ENTRY: {
- const newDirectoryIndex = state.currentDirectoryIndex.filter(
- entry => !entry.path.startsWith(action.path)
- );
- if (state.currentDirectoryIndex.length > newDirectoryIndex.length) {
- return {
- ...state,
- currentDirectoryIndex: newDirectoryIndex
- };
+ for (let i = 0; i < SearchIndex.length; i += 1) {
+ if (SearchIndex[i].path === action.path) {
+ SearchIndex.splice(i, 1);
+ i -= 1;
+ }
}
return state;
}
case types.REFLECT_CREATE_ENTRY: {
- const entryIndex = state.currentDirectoryIndex.findIndex(
- entry => entry.path === action.newEntry.path
- );
- if (entryIndex) {
+ let entryFound = false;
+ for (let i = 0; i < SearchIndex.length; i += 1) {
+ if (SearchIndex[i].path === action.path) {
+ entryFound = true;
+ }
+ }
+ if (entryFound) {
return state;
}
- return {
- ...state,
- currentDirectoryIndex: [action.newEntry, ...state.currentDirectoryIndex]
- };
+ SearchIndex.push(action.newEntry);
+ return state;
}
case types.REFLECT_RENAME_ENTRY: {
- return {
- ...state,
- currentDirectoryIndex: state.currentDirectoryIndex.map(entry => {
- if (entry.path !== action.path) {
- return entry;
- }
- return {
- ...entry,
- path: action.newPath,
- // thumbPath: getThumbFileLocationForFile(action.newPath), // disabled due performance concerns
- name: extractFileName(action.newPath),
- extension: extractFileExtension(action.newPath),
- tags: [
- ...entry.tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags
- ...extractTagsAsObjects(action.newPath) // , getTagDelimiter(state))
- ]
- };
- })
- };
+ for (let i = 0; i < SearchIndex.length; i += 1) {
+ if (SearchIndex[i].path === action.path) {
+ SearchIndex[i].path = action.newPath;
+ // thumbPath: getThumbFileLocationForFile(action.newPath), // disabled due performance concerns
+ SearchIndex[i].name = extractFileName(action.newPath);
+ SearchIndex[i].extension = extractFileExtension(action.newPath);
+ SearchIndex[i].tags = [
+ ...SearchIndex[i].tags.filter(tag => tag.type === 'sidecar'), // add only sidecar tags
+ ...extractTagsAsObjects(action.newPath) // , getTagDelimiter(state))
+ ];
+ }
+ }
+ return state;
/* const indexForRenamingInIndex = state.currentDirectoryIndex.findIndex((entry) => entry.path === action.path);
if (indexForRenamingInIndex >= 0) {
const updateEntry = {
@@ -157,21 +147,15 @@ export default (state: any = initialState, action: any) => {
return state; */
}
case types.REFLECT_UPDATE_SIDECARTAGS: {
- return {
- ...state,
- currentDirectoryIndex: state.currentDirectoryIndex.map(entry => {
- if (entry.path !== action.path) {
- return entry;
- }
- return {
- ...entry,
- tags: [
- ...entry.tags.filter(tag => tag.type === 'plain'),
- ...action.tags
- ]
- };
- })
- };
+ for (let i = 0; i < SearchIndex.length; i += 1) {
+ if (SearchIndex[i].path === action.path) {
+ SearchIndex[i].tags = [
+ ...SearchIndex[i].tags.filter(tag => tag.type === 'plain'),
+ ...action.tags
+ ];
+ }
+ }
+ return state;
/* const indexForUpdatingInIndex = state.currentDirectoryIndex.findIndex((entry) => entry.path === action.path);
if (indexForUpdatingInIndex >= 0) {
const updateEntry = {
@@ -193,18 +177,15 @@ export default (state: any = initialState, action: any) => {
return state; */
}
case types.REFLECT_UPDATE_SIDECARMETA: {
- return {
- ...state,
- currentDirectoryIndex: state.currentDirectoryIndex.map(entry => {
- if (entry.path !== action.path) {
- return entry;
- }
- return {
- ...entry,
+ for (let i = 0; i < SearchIndex.length; i += 1) {
+ if (SearchIndex[i].path === action.path) {
+ SearchIndex[i] = {
+ ...SearchIndex[i],
...action.entryMeta
};
- })
- };
+ }
+ }
+ return state;
/* const indexForUpdatingInIndex = state.currentDirectoryIndex.findIndex((entry) => entry.path === action.path);
if (indexForUpdatingInIndex >= 0) {
const updateEntry = {
@@ -242,13 +223,13 @@ export const actions = {
);
dispatch(actions.startDirectoryIndexing());
createDirectoryIndex(directoryPath, extractText)
- .then(directoryIndex => {
- dispatch(actions.indexDirectorySuccess(directoryIndex));
+ .then(() => {
+ dispatch(actions.indexDirectorySuccess());
if (Pro && Pro.Indexer) {
// && (currentLocation.persistIndex || PlatformIO.haveObjectStoreSupport())) { // always persist on s3 stores
Pro.Indexer.persistIndex(
directoryPath,
- directoryIndex,
+ SearchIndex,
currentLocation.type === locationType.TYPE_CLOUD
? '/'
: AppConfig.dirSeparator
@@ -258,7 +239,6 @@ export const actions = {
})
.catch(err => {
dispatch(actions.indexDirectoryFailure(err));
- // dispatch(actions.startDirectoryIndexing());
});
},
loadDirectoryIndex: (directoryPath: string) => (
@@ -281,8 +261,8 @@ export const actions = {
? '/'
: AppConfig.dirSeparator
)
- .then(directoryIndex => {
- dispatch(actions.indexDirectorySuccess(directoryIndex));
+ .then(() => {
+ dispatch(actions.indexDirectorySuccess());
return true;
})
.catch(err => {
@@ -331,9 +311,8 @@ export const actions = {
});
}, 50);
},
- indexDirectorySuccess: (directoryIndex: Array<Object>) => ({
- type: types.INDEX_DIRECTORY_SUCCESS,
- directoryIndex
+ indexDirectorySuccess: () => ({
+ type: types.INDEX_DIRECTORY_SUCCESS
}),
indexDirectoryFailure: (error: string) => ({
type: types.INDEX_DIRECTORY_FAILURE,
@@ -365,6 +344,5 @@ export const actions = {
};
// Selectors
-export const getIndexedEntriesCount = (state: any) =>
- state.locationIndex.currentDirectoryIndex.length;
+export const getIndexedEntriesCount = (state: any) => SearchIndex.length;
export const isIndexing = (state: any) => state.locationIndex.isIndexing;
diff --git a/app/services/search-index.ts b/app/services/search-index.ts
new file mode 100644
index 000000000..4e714ab84
--- /dev/null
+++ b/app/services/search-index.ts
@@ -0,0 +1,20 @@
+/**
+ * TagSpaces - universal file and folder organizer
+ * Copyright (C) 2020-present TagSpaces UG (haftungsbeschraenkt)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License (version 3) as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+const searchIndex = [];
+export default searchIndex;
diff --git a/app/services/search.ts b/app/services/search.ts
index 14bf521dd..0349ac951 100644
--- a/app/services/search.ts
+++ b/app/services/search.ts
@@ -20,6 +20,7 @@ import Fuse from 'fuse.js';
import jmespath from 'jmespath';
import { Tag } from '../reducers/taglibrary';
import { Pro } from '../pro';
+import SearchIndex from './search-index';
// export type FileTypeGroups = 'images' | 'notes' | 'documents' | 'audio' | 'video' | 'archives';
@@ -249,7 +250,7 @@ export default class Search {
new Promise(resolve => {
console.time('searchtime');
const jmespathQuery = constructjmespathQuery(searchQuery);
- let results = prepareIndex(locationContent);
+ let results = prepareIndex(SearchIndex);
let searched = false;
// Limiting the search to current folder only (with sub-folders)
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 8953d7107..e67c59e37 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -17,7 +17,6 @@
*/
import { saveAs } from 'file-saver';
-import uuidv1 from 'uuid';
import PlatformIO from './platform-io';
import AppConfig from '../config';
import {
@@ -32,6 +31,7 @@ import {
// import { formatDateTime4Tag } from '../utils/misc';
import versionMeta from '../version.json';
import { Tag } from '../reducers/taglibrary';
+import SearchIndex from '../services/search-index';
export interface FileSystemEntry {
uuid?: string;
@@ -66,7 +66,6 @@ export function enhanceEntry(entry: any): FileSystemEntry {
}
let sidecarDescription = '';
let sidecarColor = '';
- let uuid;
let sidecarTags = [];
if (entry.meta) {
sidecarDescription = entry.meta.description || '';
@@ -76,22 +75,29 @@ export function enhanceEntry(entry: any): FileSystemEntry {
tag.type = 'sidecar';
return true;
});
- uuid = entry.meta.uuid || undefined;
}
- const enhancedEntry = {
- uuid: uuid || uuidv1(),
+ const enhancedEntry: FileSystemEntry = {
name: entry.name,
isFile: entry.isFile,
extension: entry.isFile ? extractFileExtension(entry.name) : '',
- thumbPath: entry.thumbPath,
- description: sidecarDescription,
- color: sidecarColor,
- textContent: entry.textContent,
tags: [...sidecarTags, ...fileNameTags],
size: entry.size,
lmdt: entry.lmdt,
path: entry.path
};
+ if (sidecarDescription) {
+ enhancedEntry.description = sidecarDescription;
+ }
+ // enhancedEntry.description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae magna rhoncus, rutrum dolor id, vestibulum arcu. Maecenas scelerisque nisl quis sollicitudin dapibus. Ut pulvinar est sed nunc finibus cursus. Nam semper felis eu ex auctor, nec semper lectus sagittis. Donec dictum volutpat lorem, in mollis turpis scelerisque in. Morbi pulvinar egestas turpis, euismod suscipit leo egestas eget. Nullam ac mollis sem. \n Quisque luctus dapibus elit, sed molestie ipsum tempor quis. Sed urna turpis, mattis quis orci ac, placerat lacinia est. Pellentesque quis arcu malesuada, consequat magna ut, tincidunt eros. Aenean sodales nisl finibus pharetra blandit. Pellentesque egestas magna et lectus tempor ultricies. Phasellus sed ornare leo. Vivamus sed massa erat. \n Mauris eu dignissim justo, eget luctus nisi. Ut nec arcu quis ligula tempor porttitor. Pellentesque in pharetra quam. Nulla nec ornare magna. Phasellus interdum dictum mauris eget laoreet. In vulputate massa sem, a mattis elit turpis duis.';
+ if (entry && entry.thumbPath) {
+ enhancedEntry.thumbPath = entry.thumbPath;
+ }
+ if (entry && entry.textContent) {
+ enhancedEntry.textContent = entry.textContent;
+ }
+ if (sidecarColor) {
+ enhancedEntry.color = sidecarColor;
+ }
// console.log('Enhancing ' + entry.path); console.log(enhancedEntry);
return enhancedEntry;
}
@@ -99,16 +105,17 @@ export function enhanceEntry(entry: any): FileSystemEntry {
export function createDirectoryIndex(
directoryPath: string,
extractText: boolean = false
-): Promise<Array<Object>> {
+): Promise<number> {
const dirPath = cleanTrailingDirSeparator(directoryPath);
- if (PlatformIO.isWorkerAvailable() && !PlatformIO.haveObjectStoreSupport()) {
- // Start indexing in worker if not in the object store mode
- return PlatformIO.createDirectoryIndexInWorker(dirPath, extractText);
- }
+ // if (PlatformIO.isWorkerAvailable() && !PlatformIO.haveObjectStoreSupport()) {
+ // // Start indexing in worker if not in the object store mode
+ // return PlatformIO.createDirectoryIndexInWorker(dirPath, extractText);
+ // }
+
+ SearchIndex.length = 0;
return new Promise((resolve, reject) => {
setTimeout(() => {
- const directoryIndex = [];
let counter = 0;
console.time('createDirectoryIndex');
walkDirectory(
@@ -125,12 +132,12 @@ export function createDirectoryIndex(
console.warn('Walk canceled by ' + AppConfig.indexerLimit);
window.walkCanceled = true;
}
- directoryIndex.push(enhanceEntry(fileEntry));
+ SearchIndex.push(enhanceEntry(fileEntry));
},
directoryEntry => {
if (directoryEntry.name !== AppConfig.metaFolder) {
counter += 1;
- directoryIndex.push(enhanceEntry(directoryEntry));
+ SearchIndex.push(enhanceEntry(directoryEntry));
}
}
)
@@ -141,10 +148,10 @@ export function createDirectoryIndex(
'Directory index created ' +
dirPath +
' containing ' +
- directoryIndex.length
+ SearchIndex.length
);
console.timeEnd('createDirectoryIndex');
- resolve(directoryIndex);
+ resolve(SearchIndex.length);
return true;
})
.catch(err => {