mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-11-09 16:01:42 +08:00
Add option to silence query plan debug output for individual queries
Summary: Sometimes you have to perform a query that needs to do a table scan. For those times you don't want to silence entire classes of queries (e.g. by table name), you can now silence individual queries. Test Plan: Run locally, verify that noisy stuff disappears from logs Reviewers: evan, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D3763
This commit is contained in:
parent
313bd18913
commit
afb49b8b2f
3 changed files with 12 additions and 3 deletions
|
|
@ -29,6 +29,7 @@ export default class SearchIndexer {
|
|||
.order(modelClass.naturalSortOrder())
|
||||
.offset(indexSize)
|
||||
.limit(1)
|
||||
.silenceQueryPlanDebugOutput()
|
||||
// console.info('SearchIndexer: _getIndexCutoff query', query.sql());
|
||||
const models = await query;
|
||||
return models[0];
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ export default class ModelQuery {
|
|||
this._returnIds = false;
|
||||
this._includeJoinedData = [];
|
||||
this._count = false;
|
||||
this._logQueryPlanDebugOutput = true;
|
||||
}
|
||||
|
||||
clone() {
|
||||
|
|
@ -90,6 +91,11 @@ export default class ModelQuery {
|
|||
return this;
|
||||
}
|
||||
|
||||
silenceQueryPlanDebugOutput() {
|
||||
this._logQueryPlanDebugOutput = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Public: Add one or more where clauses to the query
|
||||
//
|
||||
// - `matchers` An {Array} of {Matcher} objects that add where clauses to the underlying query.
|
||||
|
|
|
|||
|
|
@ -296,7 +296,7 @@ class DatabaseStore extends NylasStore {
|
|||
//
|
||||
// If a query is made before the database has been opened, the query will be
|
||||
// held in a queue and run / resolved when the database is ready.
|
||||
_query(query, values = [], background = false) {
|
||||
_query(query, values = [], background = false, logQueryPlanDebugOutput = true) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this._open) {
|
||||
this._waiting.push(() => this._query(query, values).then(resolve, reject));
|
||||
|
|
@ -320,7 +320,9 @@ class DatabaseStore extends NylasStore {
|
|||
const planString = `${plan.map(row => row.detail).join('\n')} for ${query}`;
|
||||
const quiet = ['ThreadCounts', 'ThreadSearch', 'ContactSearch', 'COVERING INDEX'];
|
||||
|
||||
if (planString.includes('SCAN') && !quiet.find(str => planString.includes(str))) {
|
||||
if (planString.includes('SCAN') &&
|
||||
!quiet.find(str => planString.includes(str)) &&
|
||||
logQueryPlanDebugOutput) {
|
||||
console.log("Consider setting the .background() flag on this query to avoid blocking the event loop:")
|
||||
this._prettyConsoleLog(planString);
|
||||
}
|
||||
|
|
@ -574,7 +576,7 @@ class DatabaseStore extends NylasStore {
|
|||
// - resolves with the result of the database query.
|
||||
//
|
||||
run(modelQuery, options = {format: true}) {
|
||||
return this._query(modelQuery.sql(), [], modelQuery._background).then((result) => {
|
||||
return this._query(modelQuery.sql(), [], modelQuery._background, modelQuery._logQueryPlanDebugOutput).then((result) => {
|
||||
let transformed = modelQuery.inflateResult(result);
|
||||
if (options.format !== false) {
|
||||
transformed = modelQuery.formatResult(transformed)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue