mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-08 13:44:53 +08:00
[client-app] Add better DB logging with ENABLE_SEQUELIZE_DEBUG_LOGGING
Summary: This adds better logging to the DB You can use `ENABLE_SEQUELIZE_DEBUG_LOGGING=true` and `ENABLE_RXDB_DEBUG_LOGGING=true` to spit out the raw queries of both DBs. Test Plan: manual Reviewers: mark, halla, spang, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D4294
This commit is contained in:
parent
5196f0eee7
commit
2b67f139ea
4 changed files with 29 additions and 3 deletions
|
@ -5,7 +5,7 @@ import childProcess from 'child_process';
|
|||
import PromiseQueue from 'promise-queue';
|
||||
import {remote, ipcRenderer} from 'electron';
|
||||
import LRU from "lru-cache";
|
||||
import {ExponentialBackoffScheduler} from 'isomorphic-core';
|
||||
import {StringUtils, ExponentialBackoffScheduler} from 'isomorphic-core';
|
||||
|
||||
import NylasStore from '../../global/nylas-store';
|
||||
import Utils from '../models/utils';
|
||||
|
@ -333,6 +333,10 @@ class DatabaseStore extends NylasStore {
|
|||
}
|
||||
this._executeInBackground(query, values).then(({results, backgroundTime}) => {
|
||||
const msec = Date.now() - start;
|
||||
if (process.env.ENABLE_RXDB_DEBUG_LOGGING) {
|
||||
const q = `🔶 N1: (${msec}ms) Background: ${query}`;
|
||||
StringUtils.logTrim(q)
|
||||
}
|
||||
if (msec > 100 || DEBUG_TO_LOG) {
|
||||
const msgPrefix = msec > 100 ? 'DatabaseStore._executeInBackground took more than 100ms - ' : ''
|
||||
this._prettyConsoleLog(`${msgPrefix}${msec}msec (${backgroundTime}msec in background): ${query}`);
|
||||
|
@ -384,6 +388,11 @@ class DatabaseStore extends NylasStore {
|
|||
results = stmt[fn](values);
|
||||
const msec = Date.now() - start
|
||||
|
||||
if (process.env.ENABLE_RXDB_DEBUG_LOGGING) {
|
||||
const q = `🔶 N1: (${msec}ms) ${query}`;
|
||||
StringUtils.logTrim(q)
|
||||
}
|
||||
|
||||
if (msec > 100 || DEBUG_TO_LOG) {
|
||||
const msgPrefix = msec > 100 ? 'DatabaseStore: query took more than 100ms - ' : ''
|
||||
if (query.startsWith(`SELECT `) && DEBUG_QUERY_PLANS) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
const Sequelize = require('sequelize');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const {loadModels, HookIncrementVersionOnSave, HookTransactionLog} = require('isomorphic-core');
|
||||
const {StringUtils, loadModels, HookIncrementVersionOnSave, HookTransactionLog} = require('isomorphic-core');
|
||||
const TransactionConnector = require('./transaction-connector')
|
||||
|
||||
require('./database-extensions'); // Extends Sequelize on require
|
||||
|
@ -15,10 +15,14 @@ class LocalDatabaseConnector {
|
|||
|
||||
_sequelizePoolForDatabase(dbname) {
|
||||
const storage = NylasEnv.inSpecMode() ? ':memory:' : path.join(process.env.NYLAS_HOME, `${dbname}.sqlite`);
|
||||
const dbLog = (q, time) => {
|
||||
StringUtils.logTrim(`🔷 K2: (${time}ms) ${q}`)
|
||||
}
|
||||
return new Sequelize(dbname, '', '', {
|
||||
storage: storage,
|
||||
dialect: "sqlite",
|
||||
logging: ENABLE_SEQUELIZE_DEBUG_LOGGING ? console.log : false,
|
||||
benchmark: !!ENABLE_SEQUELIZE_DEBUG_LOGGING,
|
||||
logging: ENABLE_SEQUELIZE_DEBUG_LOGGING ? dbLog : false,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -25,4 +25,5 @@ module.exports = {
|
|||
MessageFactory: require('./src/message-factory'),
|
||||
SendUtils: require('./src/send-utils'),
|
||||
executeJasmine: require('./spec/jasmine/execute').default,
|
||||
StringUtils: require('./src/string-utils'),
|
||||
}
|
||||
|
|
12
packages/isomorphic-core/src/string-utils.es6
Normal file
12
packages/isomorphic-core/src/string-utils.es6
Normal file
|
@ -0,0 +1,12 @@
|
|||
export function logTrim(...args) {
|
||||
const g = window || global || {}
|
||||
const LOG_TRIM_SIZE = process.env.LOG_TRIM_SIZE || g.LOG_TRIM_SIZE || 256;
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
let str = args[i];
|
||||
if (str.length >= LOG_TRIM_SIZE) {
|
||||
str = `${str.slice(0, LOG_TRIM_SIZE / 2)}…${str.slice(str.length - LOG_TRIM_SIZE / 2, str.length)}`
|
||||
}
|
||||
args[i] = str;
|
||||
}
|
||||
console.log(...args);
|
||||
}
|
Loading…
Add table
Reference in a new issue