mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Mobile: Fixes #1066: Disable use of FTS when not present on device
This commit is contained in:
parent
59402cf198
commit
53513db5b5
@ -477,7 +477,7 @@ class BaseApplication {
|
|||||||
this.dbLogger_.setLevel(initArgs.logLevel);
|
this.dbLogger_.setLevel(initArgs.logLevel);
|
||||||
|
|
||||||
if (Setting.value('env') === 'dev') {
|
if (Setting.value('env') === 'dev') {
|
||||||
this.dbLogger_.setLevel(Logger.LEVEL_WARN);
|
this.dbLogger_.setLevel(Logger.LEVEL_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger_.info('Profile directory: ' + profileDir);
|
this.logger_.info('Profile directory: ' + profileDir);
|
||||||
|
@ -9,6 +9,7 @@ const { themeStyle } = require('lib/components/global-style.js');
|
|||||||
const Setting = require('lib/models/Setting.js');
|
const Setting = require('lib/models/Setting.js');
|
||||||
const shared = require('lib/components/shared/config-shared.js');
|
const shared = require('lib/components/shared/config-shared.js');
|
||||||
const SyncTargetRegistry = require('lib/SyncTargetRegistry');
|
const SyncTargetRegistry = require('lib/SyncTargetRegistry');
|
||||||
|
const { reg } = require('lib/registry.js');
|
||||||
import VersionInfo from 'react-native-version-info';
|
import VersionInfo from 'react-native-version-info';
|
||||||
|
|
||||||
class ConfigScreenComponent extends BaseScreenComponent {
|
class ConfigScreenComponent extends BaseScreenComponent {
|
||||||
@ -248,8 +249,20 @@ class ConfigScreenComponent extends BaseScreenComponent {
|
|||||||
);
|
);
|
||||||
|
|
||||||
settingComps.push(
|
settingComps.push(
|
||||||
<View key="version_info" style={this.styles().settingContainer}>
|
<View key="version_info_app" style={this.styles().settingContainer}>
|
||||||
<Text key="version" style={this.styles().settingText}>Version {VersionInfo.appVersion}</Text>
|
<Text style={this.styles().settingText}>{_('Joplin v%s', VersionInfo.appVersion)}</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
|
settingComps.push(
|
||||||
|
<View key="version_info_db" style={this.styles().settingContainer}>
|
||||||
|
<Text style={this.styles().settingText}>{_('Database v%s', reg.db().version())}</Text>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
|
settingComps.push(
|
||||||
|
<View key="version_info_fts" style={this.styles().settingContainer}>
|
||||||
|
<Text style={this.styles().settingText}>{_('FTS enabled: %d', this.props.settings['db.ftsEnabled'])}</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class FolderScreenComponent extends BaseScreenComponent {
|
|||||||
saveButtonDisabled={saveButtonDisabled}
|
saveButtonDisabled={saveButtonDisabled}
|
||||||
onSaveButtonPress={() => this.saveFolderButton_press()}
|
onSaveButtonPress={() => this.saveFolderButton_press()}
|
||||||
/>
|
/>
|
||||||
<TextInput selectionColor={theme.textSelectionColor} style={this.styles().textInput} autoFocus={true} value={this.state.folder.title} onChangeText={(text) => this.title_changeText(text)} />
|
<TextInput underlineColorAndroid={theme.strongDividerColor} selectionColor={theme.textSelectionColor} style={this.styles().textInput} autoFocus={true} value={this.state.folder.title} onChangeText={(text) => this.title_changeText(text)} />
|
||||||
<dialogs.DialogBox ref={dialogbox => { this.dialogbox = dialogbox }}/>
|
<dialogs.DialogBox ref={dialogbox => { this.dialogbox = dialogbox }}/>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
|
@ -597,8 +597,9 @@ class NoteScreenComponent extends BaseScreenComponent {
|
|||||||
this.saveOneProperty('body', newBody);
|
this.saveOneProperty('body', newBody);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Currently keyword highlighting is supported only when FTS is available.
|
||||||
let keywords = [];
|
let keywords = [];
|
||||||
if (this.props.searchQuery) {
|
if (this.props.searchQuery && !!this.props.ftsEnabled) {
|
||||||
const parsedQuery = SearchEngine.instance().parseQuery(this.props.searchQuery);
|
const parsedQuery = SearchEngine.instance().parseQuery(this.props.searchQuery);
|
||||||
keywords = SearchEngine.instance().allParsedQueryTerms(parsedQuery);
|
keywords = SearchEngine.instance().allParsedQueryTerms(parsedQuery);
|
||||||
}
|
}
|
||||||
@ -769,6 +770,7 @@ const NoteScreen = connect(
|
|||||||
folders: state.folders,
|
folders: state.folders,
|
||||||
searchQuery: state.searchQuery,
|
searchQuery: state.searchQuery,
|
||||||
theme: state.settings.theme,
|
theme: state.settings.theme,
|
||||||
|
ftsEnabled: state.settings['db.ftsEnabled'],
|
||||||
sharedData: state.sharedData,
|
sharedData: state.sharedData,
|
||||||
showAdvancedOptions: state.settings.showAdvancedOptions,
|
showAdvancedOptions: state.settings.showAdvancedOptions,
|
||||||
};
|
};
|
||||||
|
@ -106,22 +106,22 @@ class SearchScreenComponent extends BaseScreenComponent {
|
|||||||
let notes = []
|
let notes = []
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
notes = await SearchEngineUtils.notesForQuery(query);
|
|
||||||
|
|
||||||
// Keeping the code below in case of compatibility issue with old versions
|
if (!!this.props.settings['db.ftsEnabled']) {
|
||||||
// of Android and SQLite FTS.
|
notes = await SearchEngineUtils.notesForQuery(query);
|
||||||
|
} else {
|
||||||
|
let p = query.split(' ');
|
||||||
|
let temp = [];
|
||||||
|
for (let i = 0; i < p.length; i++) {
|
||||||
|
let t = p[i].trim();
|
||||||
|
if (!t) continue;
|
||||||
|
temp.push(t);
|
||||||
|
}
|
||||||
|
|
||||||
// let p = query.split(' ');
|
notes = await Note.previews(null, {
|
||||||
// let temp = [];
|
anywherePattern: '*' + temp.join('*') + '*',
|
||||||
// for (let i = 0; i < p.length; i++) {
|
});
|
||||||
// let t = p[i].trim();
|
}
|
||||||
// if (!t) continue;
|
|
||||||
// temp.push(t);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// notes = await Note.previews(null, {
|
|
||||||
// anywherePattern: '*' + temp.join('*') + '*',
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.isMounted_) return;
|
if (!this.isMounted_) return;
|
||||||
@ -193,6 +193,7 @@ const SearchScreen = connect(
|
|||||||
return {
|
return {
|
||||||
query: state.searchQuery,
|
query: state.searchQuery,
|
||||||
theme: state.settings.theme,
|
theme: state.settings.theme,
|
||||||
|
settings: state.settings,
|
||||||
noteSelectionEnabled: state.noteSelectionEnabled,
|
noteSelectionEnabled: state.noteSelectionEnabled,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,7 @@ class JoplinDatabase extends Database {
|
|||||||
super(driver);
|
super(driver);
|
||||||
this.initialized_ = false;
|
this.initialized_ = false;
|
||||||
this.tableFields_ = null;
|
this.tableFields_ = null;
|
||||||
|
this.version_ = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
initialized() {
|
initialized() {
|
||||||
@ -270,7 +271,9 @@ class JoplinDatabase extends Database {
|
|||||||
// version of the database, so that migration is not run in this case.
|
// version of the database, so that migration is not run in this case.
|
||||||
if (currentVersionIndex < 0) throw new Error('Unknown profile version. Most likely this is an old version of Joplin, while the profile was created by a newer version. Please upgrade Joplin at https://joplin.cozic.net and try again.');
|
if (currentVersionIndex < 0) throw new Error('Unknown profile version. Most likely this is an old version of Joplin, while the profile was created by a newer version. Please upgrade Joplin at https://joplin.cozic.net and try again.');
|
||||||
|
|
||||||
if (currentVersionIndex == existingDatabaseVersions.length - 1) return false;
|
if (currentVersionIndex == existingDatabaseVersions.length - 1) return fromVersion;
|
||||||
|
|
||||||
|
let latestVersion = fromVersion;
|
||||||
|
|
||||||
while (currentVersionIndex < existingDatabaseVersions.length - 1) {
|
while (currentVersionIndex < existingDatabaseVersions.length - 1) {
|
||||||
const targetVersion = existingDatabaseVersions[currentVersionIndex + 1];
|
const targetVersion = existingDatabaseVersions[currentVersionIndex + 1];
|
||||||
@ -472,14 +475,42 @@ class JoplinDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
queries.push({ sql: 'UPDATE version SET version = ?', params: [targetVersion] });
|
queries.push({ sql: 'UPDATE version SET version = ?', params: [targetVersion] });
|
||||||
await this.transactionExecBatch(queries);
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.transactionExecBatch(queries);
|
||||||
|
} catch (error) {
|
||||||
|
if (targetVersion === 15) {
|
||||||
|
this.logger().warn('Could not upgrade to database v15 - FTS feature will not be used', error);
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
latestVersion = targetVersion;
|
||||||
|
|
||||||
currentVersionIndex++;
|
currentVersionIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return latestVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
async ftsEnabled() {
|
||||||
|
try {
|
||||||
|
await this.selectOne('SELECT count(*) FROM notes_fts');
|
||||||
|
} catch (error) {
|
||||||
|
this.logger().warn('FTS check failed', error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger().info('FTS check succeeded');
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version() {
|
||||||
|
return this.version_;
|
||||||
|
}
|
||||||
|
|
||||||
async initialize() {
|
async initialize() {
|
||||||
this.logger().info('Checking for database schema update...');
|
this.logger().info('Checking for database schema update...');
|
||||||
|
|
||||||
@ -496,10 +527,12 @@ class JoplinDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const version = !versionRow ? 0 : versionRow.version;
|
const version = !versionRow ? 0 : versionRow.version;
|
||||||
|
this.version_ = version;
|
||||||
this.logger().info('Current database version', version);
|
this.logger().info('Current database version', version);
|
||||||
|
|
||||||
const upgraded = await this.upgradeDatabase(version);
|
const newVersion = await this.upgradeDatabase(version);
|
||||||
if (upgraded) await this.refreshTableFields();
|
this.version_ = newVersion;
|
||||||
|
if (newVersion !== version) await this.refreshTableFields();
|
||||||
|
|
||||||
this.tableFields_ = {};
|
this.tableFields_ = {};
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ class Setting extends BaseModel {
|
|||||||
|
|
||||||
'collapsedFolderIds': { value: [], type: Setting.TYPE_ARRAY, public: false },
|
'collapsedFolderIds': { value: [], type: Setting.TYPE_ARRAY, public: false },
|
||||||
|
|
||||||
|
'db.ftsEnabled': { value: -1, type: Setting.TYPE_INT, public: false },
|
||||||
'encryption.enabled': { value: false, type: Setting.TYPE_BOOL, public: false },
|
'encryption.enabled': { value: false, type: Setting.TYPE_BOOL, public: false },
|
||||||
'encryption.activeMasterKeyId': { value: '', type: Setting.TYPE_STRING, public: false },
|
'encryption.activeMasterKeyId': { value: '', type: Setting.TYPE_STRING, public: false },
|
||||||
'encryption.passwordCache': { value: {}, type: Setting.TYPE_OBJECT, public: false, secure: true },
|
'encryption.passwordCache': { value: {}, type: Setting.TYPE_OBJECT, public: false, secure: true },
|
||||||
|
@ -417,7 +417,13 @@ async function initialize(dispatch) {
|
|||||||
if (!locale) locale = defaultLocale();
|
if (!locale) locale = defaultLocale();
|
||||||
Setting.setValue('locale', closestSupportedLocale(locale));
|
Setting.setValue('locale', closestSupportedLocale(locale));
|
||||||
if (Setting.value('env') === 'dev') Setting.setValue('sync.target', SyncTargetRegistry.nameToId('onedrive_dev'));
|
if (Setting.value('env') === 'dev') Setting.setValue('sync.target', SyncTargetRegistry.nameToId('onedrive_dev'));
|
||||||
Setting.setValue('firstStart', 0)
|
Setting.setValue('firstStart', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Setting.value('db.ftsEnabled') === -1) {
|
||||||
|
const ftsEnabled = await db.ftsEnabled();
|
||||||
|
Setting.setValue('db.ftsEnabled', ftsEnabled ? 1 : 0);
|
||||||
|
reg.logger().info('db.ftsEnabled = ', Setting.value('db.ftsEnabled'));
|
||||||
}
|
}
|
||||||
|
|
||||||
reg.logger().info('Sync target: ' + Setting.value('sync.target'));
|
reg.logger().info('Sync target: ' + Setting.value('sync.target'));
|
||||||
@ -481,6 +487,7 @@ async function initialize(dispatch) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
alert('Initialization error: ' + error.message);
|
||||||
reg.logger().error('Initialization error:', error);
|
reg.logger().error('Initialization error:', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user