Skip to content

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

Tsn473 disable indexing on location opening (#1217)

Ilianc0da894bfde0
diff --git a/app/components/EntryContainer.tsx b/app/components/EntryContainer.tsx
index 12a4ba55e..a72e08d7b 100644
--- a/app/components/EntryContainer.tsx
+++ b/app/components/EntryContainer.tsx
@@ -1062,8 +1062,9 @@ const EntryContainer = (props: Props) => {
removeAllTags={props.removeAllTags}
selectedEntries={openedFile ? [openedFile] : []}
/>
- {/* <a href="#" id="downloadFile">
- </a> */}
+ <a href="#" id="downloadFile">
+ &nbsp;
+ </a>
<SplitPane
split="horizontal"
resizerStyle={{ backgroundColor: props.theme.palette.divider }}
diff --git a/app/components/Search.tsx b/app/components/Search.tsx
index 85d280b55..9f092430f 100644
--- a/app/components/Search.tsx
+++ b/app/components/Search.tsx
@@ -431,6 +431,9 @@ class Search extends React.Component<Props, State> {
render() {
const { classes, indexing, indexedEntriesCount } = this.props;
+ const indexStatus = indexedEntriesCount
+ ? indexedEntriesCount + ' indexed entries'
+ : '';
return (
<div className={classes.panel} style={this.props.style}>
<CustomLogo />
@@ -444,12 +447,9 @@ class Search extends React.Component<Props, State> {
<Typography
variant="caption"
className={classes.header}
- title="Indexed entries in the current location"
style={{ alignSelf: 'center', paddingLeft: 5, display: 'block' }}
>
- {indexing
- ? 'disabled while indexing...'
- : indexedEntriesCount + ' indexed entries'}
+ {indexStatus}
</Typography>
<IconButton
style={{ marginLeft: 'auto' }}
diff --git a/app/config.ts b/app/config.ts
index 2647518ff..8e9c4cd5f 100644
--- a/app/config.ts
+++ b/app/config.ts
@@ -41,6 +41,7 @@ export const AppConfig = {
maxThumbSize: 400,
thumbBgColor: '#FFFFFF',
indexerLimit: 200000,
+ maxIndexAge: 10 * 60 * 1000, // 10 minutes
// maxSearchResult: 1000,
defaultFileColor: '#808080',
defaultFolderColor: '#555', // transparent #FDEEBD #ff791b #2c001e #880e4f
diff --git a/app/reducers/app.ts b/app/reducers/app.ts
index f5885dba1..391a60b9a 100644
--- a/app/reducers/app.ts
+++ b/app/reducers/app.ts
@@ -1153,18 +1153,7 @@ export const actions = {
);
dispatch(actions.setReadOnlyMode(location.isReadOnly || false));
if (location.uuid !== currentLocationId) {
- if (location.persistIndex) {
- dispatch(
- LocationIndexActions.loadDirectoryIndex(location.paths[0])
- );
- } else {
- dispatch(
- LocationIndexActions.createDirectoryIndex(
- location.paths[0],
- location.fullTextIndex
- )
- );
- }
+ dispatch(LocationIndexActions.clearDirectoryIndex());
}
dispatch(actions.setCurrentLocationId(location.uuid));
dispatch(actions.loadDirectoryContent(location.paths[0]));
@@ -1181,20 +1170,10 @@ export const actions = {
PlatformIO.disableObjectStoreSupport();
});
} else {
- // if (location.type === locationType.TYPE_LOCAL) {
PlatformIO.disableObjectStoreSupport();
dispatch(actions.setReadOnlyMode(location.isReadOnly || false));
if (location.uuid !== currentLocationId) {
- if (location.persistIndex) {
- dispatch(LocationIndexActions.loadDirectoryIndex(location.paths[0]));
- } else {
- dispatch(
- LocationIndexActions.createDirectoryIndex(
- location.paths[0],
- location.fullTextIndex
- )
- );
- }
+ dispatch(LocationIndexActions.clearDirectoryIndex());
}
dispatch(actions.setCurrentLocationId(location.uuid));
dispatch(actions.loadDirectoryContent(location.paths[0]));
@@ -1295,8 +1274,8 @@ export const actions = {
entry => entry.path === entryPath
);
if (currentEntry) {
- if (currentEntry.url) {
- entryForOpening.url = currentEntry.url;
+ if (PlatformIO.haveObjectStoreSupport()) {
+ entryForOpening.url = PlatformIO.getURLforPath(currentEntry.path);
}
if (currentEntry.perspective) {
entryForOpening.perspective = currentEntry.perspective;
diff --git a/app/reducers/location-index.ts b/app/reducers/location-index.ts
index a08f11c31..754d8619a 100644
--- a/app/reducers/location-index.ts
+++ b/app/reducers/location-index.ts
@@ -67,6 +67,7 @@ export default (state: any = initialState, action: any) => {
case types.INDEX_DIRECTORY_CLEAR: {
// GlobalSearch.index.length = 0;
GlobalSearch.index.splice(0, GlobalSearch.index.length);
+ GlobalSearch.indexLoadedOn = undefined;
return {
...state,
isIndexing: false
@@ -239,36 +240,36 @@ export const actions = {
console.warn('Resolution is faled!', e);
});
},
- loadDirectoryIndex: (
- directoryPath: string,
- isCurrentLocation: boolean = true
- ) => (dispatch: (actions: Object) => void) => {
- dispatch(actions.startDirectoryIndexing());
- dispatch(
- AppActions.showNotification(i18n.t('core:loadingIndex'), 'default', true)
- );
- if (Pro && Pro.Indexer.loadIndex) {
- Pro.Indexer.loadIndex(directoryPath, PlatformIO.getDirSeparator())
- .then(directoryIndex => {
- if (isCurrentLocation) {
- // Load index only if current location
- GlobalSearch.index = directoryIndex;
- }
- dispatch(actions.indexDirectorySuccess());
- return true;
- })
- .catch(err => {
- dispatch(actions.indexDirectoryFailure(err));
- dispatch(
- AppActions.showNotification(
- i18n.t('core:loadingIndexFailed'),
- 'warning',
- true
- )
- );
- });
- }
- },
+ // loadDirectoryIndex: (
+ // directoryPath: string,
+ // isCurrentLocation: boolean = true
+ // ) => (dispatch: (actions: Object) => void) => {
+ // dispatch(actions.startDirectoryIndexing());
+ // dispatch(
+ // AppActions.showNotification(i18n.t('core:loadingIndex'), 'default', true)
+ // );
+ // if (Pro && Pro.Indexer.loadIndex) {
+ // Pro.Indexer.loadIndex(directoryPath, PlatformIO.getDirSeparator())
+ // .then(directoryIndex => {
+ // if (isCurrentLocation) {
+ // // Load index only if current location
+ // GlobalSearch.index = directoryIndex;
+ // }
+ // dispatch(actions.indexDirectorySuccess());
+ // return true;
+ // })
+ // .catch(err => {
+ // dispatch(actions.indexDirectoryFailure(err));
+ // dispatch(
+ // AppActions.showNotification(
+ // i18n.t('core:loadingIndexFailed'),
+ // 'warning',
+ // true
+ // )
+ // );
+ // });
+ // }
+ // },
clearDirectoryIndex: () => ({
type: types.INDEX_DIRECTORY_CLEAR
}),
@@ -296,31 +297,43 @@ export const actions = {
AppActions.showNotification(i18n.t('core:searching'), 'default', false)
);
dispatch(actions.setSearchQuery(searchQuery));
- let directoryIndex = GlobalSearch.index;
setTimeout(async () => {
// Workaround used to show the start search notification
- if (searchQuery.forceIndexing) {
+ const currentTime = new Date().getTime();
+ const indexAge = GlobalSearch.indexLoadedOn
+ ? currentTime - GlobalSearch.indexLoadedOn
+ : 0;
+ if (
+ GlobalSearch.index.length < 1 ||
+ searchQuery.forceIndexing ||
+ indexAge > AppConfig.maxIndexAge
+ ) {
const currentPath = currentLocation.paths[0];
console.log('Start creating index for : ' + currentPath);
- directoryIndex = await createDirectoryIndex(
- currentPath,
- currentLocation.fullTextIndex
- );
- if (Pro && Pro.Indexer && Pro.Indexer.persistIndex) {
- Pro.Indexer.persistIndex(
+ if (currentLocation.persistIndex && Pro && Pro.Indexer.loadIndex) {
+ GlobalSearch.index = await Pro.Indexer.loadIndex(
currentPath,
- directoryIndex,
PlatformIO.getDirSeparator()
);
+ } else {
+ GlobalSearch.index = await createDirectoryIndex(
+ currentPath,
+ currentLocation.fullTextIndex
+ );
+ if (Pro && Pro.Indexer && Pro.Indexer.persistIndex) {
+ Pro.Indexer.persistIndex(
+ currentPath,
+ GlobalSearch.index,
+ PlatformIO.getDirSeparator()
+ );
+ }
+ }
+ if (GlobalSearch.index && GlobalSearch.index.length > 0) {
+ GlobalSearch.indexLoadedOn = new Date().getTime();
}
}
Search.searchLocationIndex(GlobalSearch.index, searchQuery)
.then(searchResults => {
- if (currentLocation.type === locationType.TYPE_CLOUD) {
- searchResults.forEach((entry: FileSystemEntry) => {
- entry.url = PlatformIO.getURLforPath(entry.path);
- });
- }
dispatch(AppActions.setSearchResults(searchResults));
dispatch(AppActions.hideNotifications());
return true;
@@ -354,7 +367,7 @@ export const actions = {
// Preparing for global search
dispatch(AppActions.setSearchResults([]));
- if (currentLocation.type === locationType.TYPE_CLOUD) {
+ if (currentLocation && currentLocation.type === locationType.TYPE_CLOUD) {
PlatformIO.disableObjectStoreSupport();
}
window.walkCanceled = false;
@@ -417,7 +430,6 @@ export const actions = {
(entry: FileSystemEntry) => {
// Excluding s3 folders from global search
if (entry && entry.isFile) {
- entry.url = PlatformIO.getURLforPath(entry.path);
return entry;
}
}
diff --git a/app/services/search-index.ts b/app/services/search-index.ts
index 9149b8da8..19849844e 100644
--- a/app/services/search-index.ts
+++ b/app/services/search-index.ts
@@ -17,6 +17,7 @@
*/
const GlobalSearch = {
+ indexLoadedOn: undefined,
index: []
};
export default GlobalSearch;
diff --git a/app/services/utils-io.ts b/app/services/utils-io.ts
index 4f289b363..34132ff42 100644
--- a/app/services/utils-io.ts
+++ b/app/services/utils-io.ts
@@ -91,11 +91,6 @@ export function enhanceDirectoryContent(
return true;
}
- if (isCloudLocation) {
- // eslint-disable-next-line no-param-reassign
- entry.url = PlatformIO.getURLforPath(entry.path);
- }
-
const enhancedEntry = enhanceEntry(entry);
directoryContent.push(enhancedEntry);
if (