test with better-sqlite3 bindings

This commit is contained in:
Audric Ackermann 2021-07-08 13:00:20 +10:00
parent 4fbb0d48f2
commit b385a9b101
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
10 changed files with 3151 additions and 2113 deletions

2583
app/sql.js

File diff suppressed because it is too large Load diff

View file

@ -20,14 +20,14 @@ function initialize() {
}
initialized = true;
ipcMain.on(SQL_CHANNEL_KEY, async (event, jobId, callName, ...args) => {
ipcMain.on(SQL_CHANNEL_KEY, (event, jobId, callName, ...args) => {
try {
const fn = sql[callName];
if (!fn) {
throw new Error(`sql channel: ${callName} is not an available function`);
}
const result = await fn(...args);
const result = fn(...args);
event.sender.send(`${SQL_CHANNEL_KEY}-done`, jobId, null, result);
} catch (error) {
@ -40,7 +40,7 @@ function initialize() {
}
});
ipcMain.on(ERASE_SQL_KEY, async event => {
ipcMain.on(ERASE_SQL_KEY, event => {
try {
removeUserConfig();
removeEphemeralConfig();

13
main.js
View file

@ -679,7 +679,7 @@ async function removeDB() {
async function showMainWindow(sqlKey, passwordAttempt = false) {
const userDataPath = await getRealPath(app.getPath('userData'));
await sql.initialize({
sql.initialize({
configDir: userDataPath,
key: sqlKey,
messages: locale.messages,
@ -897,7 +897,8 @@ ipc.on('set-password', async (event, passPhrase, oldPhrase) => {
try {
// Check if the hash we have stored matches the hash of the old passphrase.
const hash = await sql.getPasswordHash();
const hash = sql.getPasswordHash();
const hashMatches = oldPhrase && passwordUtil.matchesHash(oldPhrase, hash);
if (hash && !hashMatches) {
const incorrectOldPassword = locale.messages.invalidOldPassword;
@ -909,13 +910,13 @@ ipc.on('set-password', async (event, passPhrase, oldPhrase) => {
if (_.isEmpty(passPhrase)) {
const defaultKey = getDefaultSQLKey();
await sql.setSQLPassword(defaultKey);
await sql.removePasswordHash();
sql.setSQLPassword(defaultKey);
sql.removePasswordHash();
userConfig.set('dbHasPassword', false);
} else {
await sql.setSQLPassword(passPhrase);
sql.setSQLPassword(passPhrase);
const newHash = passwordUtil.generateHash(passPhrase);
await sql.savePasswordHash(newHash);
sql.savePasswordHash(newHash);
userConfig.set('dbHasPassword', true);
}

View file

@ -40,7 +40,8 @@
"transpile": "tsc --incremental",
"transpile:watch": "tsc -w",
"clean-transpile": "rimraf 'ts/**/*.js ts/*.js' 'ts/*.js.map' 'ts/**/*.js.map' && rimraf tsconfig.tsbuildinfo;",
"ready": "yarn clean-transpile; yarn grunt && yarn lint-full && yarn test"
"ready": "yarn clean-transpile; yarn grunt && yarn lint-full && yarn test",
"build:webpack:sql-worker": "cross-env NODE_ENV=production webpack -c webpack-sql-worker.config.ts"
},
"dependencies": {
"@journeyapps/sqlcipher": "https://github.com/Bilb/node-sqlcipher.git#98039b72e197171b69358b900bc179ffc22e1f32",
@ -49,6 +50,7 @@
"abort-controller": "3.0.0",
"auto-bind": "^4.0.0",
"backbone": "1.3.3",
"better-sqlite3": "https://github.com/signalapp/better-sqlite3#2fa02d2484e9f9a10df5ac7ea4617fb2dff30006",
"blob-util": "1.3.0",
"blueimp-canvas-to-blob": "3.14.0",
"blueimp-load-image": "2.18.0",
@ -124,6 +126,8 @@
},
"devDependencies": {
"@types/backbone": "^1.4.2",
"@types/better-sqlite3": "5.4.1",
"@types/blueimp-load-image": "^2.23.8",
"@types/buffer-crc32": "^0.2.0",
"@types/bytebuffer": "^5.0.41",
@ -162,6 +166,7 @@
"@types/styled-components": "^5.1.4",
"@types/tmp": "^0.2.0",
"@types/uuid": "3.4.4",
"@types/webpack": "^5.28.0",
"arraybuffer-loader": "1.0.3",
"asar": "0.14.0",
"bower": "1.8.2",
@ -205,7 +210,9 @@
"tslint-microsoft-contrib": "6.0.0",
"tslint-react": "3.6.0",
"typescript": "^4.2.3",
"webpack": "4.4.1"
"webpack": "5.30.0",
"webpack-cli": "4.6.0",
"webpack-dev-server": "3.11.2"
},
"engines": {
"node": "^10.19.0"
@ -260,6 +267,10 @@
],
"icon": "build/icons/png"
},
"asarUnpack": [
"ts/sql/mainWorker.bundle.js",
"node_modules/better-sqlite3/build/Release/better_sqlite3.node"
],
"deb": {
"depends": [
"libnotify4",
@ -328,6 +339,9 @@
"!node_modules/@journeyapps/sqlcipher/build/*",
"!node_modules/@journeyapps/sqlcipher/lib/binding/node-*",
"!build/*.js",
"!node_modules/better-sqlite3/deps/*",
"!node_modules/better-sqlite3/src/*",
"node_modules/better-sqlite3/build/Release/better_sqlite3.node",
"!dev-app-update.yml"
],
"afterPack": "./build/afterPackHook.js"

View file

@ -50,7 +50,6 @@ export class SearchResults extends React.Component<Props> {
</div>
{conversations.map(conversation => (
<MemoConversationListItemWithDetails
key={conversation.phoneNumber}
{...conversation}
onClick={openConversationExternal}
/>
@ -85,11 +84,7 @@ export class SearchResults extends React.Component<Props> {
<div className="module-search-results__contacts">
<div className="module-search-results__contacts-header">{header}</div>
{items.map(contact => (
<MemoConversationListItemWithDetails
key={contact.phoneNumber}
{...contact}
onClick={openConversationExternal}
/>
<MemoConversationListItemWithDetails {...contact} onClick={openConversationExternal} />
))}
</div>
);

View file

@ -39,7 +39,6 @@ export class LeftPaneContactSection extends React.Component<Props> {
return (
<MemoConversationListItemWithDetails
key={item.id}
style={style}
{...item}
onClick={this.props.openConversationExternal}

View file

@ -91,7 +91,6 @@ export class LeftPaneMessageSection extends React.Component<Props, State> {
return (
<MemoConversationListItemWithDetails
key={key}
style={style}
{...conversation}
onClick={openConversationExternal}

View file

@ -215,6 +215,9 @@ function _cleanData(data: any): any {
} else if (_.isObject(value)) {
// eslint-disable-next-line no-param-reassign
data[key] = _cleanData(value);
} else if (_.isBoolean(value)) {
// eslint-disable-next-line no-param-reassign
data[key] = value ? 1 : 0;
} else if (
typeof value !== 'string' &&
typeof value !== 'number' &&
@ -863,7 +866,7 @@ export async function saveAttachmentDownloadJob(job: any): Promise<void> {
await channels.saveAttachmentDownloadJob(job);
}
export async function setAttachmentDownloadJobPending(id: string, pending: boolean): Promise<void> {
await channels.setAttachmentDownloadJobPending(id, pending);
await channels.setAttachmentDownloadJobPending(id, pending ? 1 : 0);
}
export async function resetAttachmentDownloadPending(): Promise<void> {
await channels.resetAttachmentDownloadPending();

View file

@ -178,7 +178,7 @@ export async function incrementBadPathCountOrDrop(snodeEd25519: string) {
const guardNodeEd25519 = onionPaths[pathWithSnodeIndex][0].pubkey_ed25519;
window?.log?.info(
`\t\tincrementBadPathCountOrDrop starting with guard ${ed25519Str(guardNodeEd25519)}`
`incrementBadPathCountOrDrop starting with guard ${ed25519Str(guardNodeEd25519)}`
);
const pathWithIssues = onionPaths[pathWithSnodeIndex];

2628
yarn.lock

File diff suppressed because it is too large Load diff