Skip to content

Commit

Permalink
Added concept of ghost-query debug mode
Browse files Browse the repository at this point in the history
- Outputting all queries is too much debug info for normal dev
- Use DEBUG=ghost:*,ghost-query to debug queries
- Or just DEBUG=ghost-query
  • Loading branch information
ErisDS committed Nov 1, 2017
1 parent 9b54ed0 commit 5319fd4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions core/server/models/plugins/include-count.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var debug = require('ghost-ignition').debug('models:plugin:include-count'),
var _debug = require('ghost-ignition').debug._base,
debug = _debug('ghost-query'),
_ = require('lodash');

module.exports = function (Bookshelf) {
Expand Down Expand Up @@ -61,15 +62,23 @@ module.exports = function (Bookshelf) {
fetch: function () {
this.addCounts.apply(this, arguments);

debug('QUERY', this.query().toQuery());
// Useful when debugging no. database queries, GQL, etc
// To output this, use DEBUG=ghost:*,ghost-query
if (_debug.enabled('ghost-query')) {
debug('QUERY', this.query().toQuery());
}

// Call parent fetch
return modelProto.fetch.apply(this, arguments);
},
fetchAll: function () {
this.addCounts.apply(this, arguments);

debug('QUERY', this.query().toQuery());
// Useful when debugging no. database queries, GQL, etc
// To output this, use DEBUG=ghost:*,ghost-query
if (_debug.enabled('ghost-query')) {
debug('QUERY', this.query().toQuery());
}

// Call parent fetchAll
return modelProto.fetchAll.apply(this, arguments);
Expand Down

0 comments on commit 5319fd4

Please sign in to comment.