不要怂,就是干,撸起袖子干!

Commit 2ee8d99b by Mick Hansen Committed by Jan Aagaard Meier

im not very good at cherry-picking

1 parent 236b0e76
Showing with 17 additions and 1 deletions
...@@ -2,6 +2,8 @@ var Utils = require("./utils") ...@@ -2,6 +2,8 @@ var Utils = require("./utils")
, DAO = require("./dao") , DAO = require("./dao")
, DataTypes = require("./data-types") , DataTypes = require("./data-types")
var tk = require('timekit');
module.exports = (function() { module.exports = (function() {
var DAOFactory = function(name, attributes, options) { var DAOFactory = function(name, attributes, options) {
var self = this var self = this
...@@ -112,6 +114,7 @@ module.exports = (function() { ...@@ -112,6 +114,7 @@ module.exports = (function() {
} }
DAOFactory.prototype.find = function(options) { DAOFactory.prototype.find = function(options) {
var start = tk.time();
// no options defined? // no options defined?
// return an emitter which emits null // return an emitter which emits null
if([null, undefined].indexOf(options) > -1) { if([null, undefined].indexOf(options) > -1) {
...@@ -145,6 +148,7 @@ module.exports = (function() { ...@@ -145,6 +148,7 @@ module.exports = (function() {
options.limit = 1 options.limit = 1
this.daoFactoryManager.sequelize._metric('Model.find', tk.time() - start);
return this.QueryInterface.select(this, this.tableName, options, { plain: true }) return this.QueryInterface.select(this, this.tableName, options, { plain: true })
} }
...@@ -171,7 +175,7 @@ module.exports = (function() { ...@@ -171,7 +175,7 @@ module.exports = (function() {
return this.QueryInterface.rawSelect(this.tableName, options, 'min') return this.QueryInterface.rawSelect(this.tableName, options, 'min')
} }
var tk = require('timekit');
DAOFactory.prototype.build = function(values, options) { DAOFactory.prototype.build = function(values, options) {
var start = tk.time(); var start = tk.time();
var instance = new DAO(values, Utils._.extend(this.options, this.attributes, { hasPrimaryKeys: this.hasPrimaryKeys })) var instance = new DAO(values, Utils._.extend(this.options, this.attributes, { hasPrimaryKeys: this.hasPrimaryKeys }))
......
var Utils = require('./utils') var Utils = require('./utils')
, DataTypes = require('./data-types') , DataTypes = require('./data-types')
var tk = require('timekit');
module.exports = (function() { module.exports = (function() {
var QueryInterface = function(sequelize) { var QueryInterface = function(sequelize) {
this.sequelize = sequelize this.sequelize = sequelize
...@@ -195,7 +197,17 @@ module.exports = (function() { ...@@ -195,7 +197,17 @@ module.exports = (function() {
} }
QueryInterface.prototype.select = function(factory, tableName, options, queryOptions) { QueryInterface.prototype.select = function(factory, tableName, options, queryOptions) {
var start = tk.time();
// Not pretty, but a lot of convenience because you dont have to wrap everything!
if(options && !Utils._.isEmpty(options) && !options.hasOwnProperty('order') && !options.hasOwnProperty('group') && !options.hasOwnProperty('limit')) {
if (!options.hasOwnProperty('where')) {
options = { where: options };
} else {
if (Utils._.isEmpty(options.where)) options = {};
}
}
var sql = this.QueryGenerator.selectQuery(tableName, options) var sql = this.QueryGenerator.selectQuery(tableName, options)
this.sequelize._metric('QueryInterface.select', tk.time() - start);
return queryAndEmit.call(this, [sql, factory, queryOptions], 'select') return queryAndEmit.call(this, [sql, factory, queryOptions], 'select')
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!