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

Commit 09dcaca3 by Sushant Committed by GitHub

perf: some improvements / cleanup (#9576)

1 parent 2c50b7ee
...@@ -2,6 +2,7 @@ docs ...@@ -2,6 +2,7 @@ docs
esdoc esdoc
examples examples
test test
scripts
README.md README.md
.watchr.js .watchr.js
changelog.md changelog.md
......
...@@ -24,7 +24,7 @@ install: ...@@ -24,7 +24,7 @@ install:
build: off build: off
before_test: before_test:
- ps: . .\appveyor-setup.ps1 - ps: . .\scripts\appveyor-setup.ps1
test_script: test_script:
- 'IF "%COVERAGE%" == "true" (npm run cover) ELSE (npm test)' - 'IF "%COVERAGE%" == "true" (npm run cover) ELSE (npm test)'
......
...@@ -724,7 +724,7 @@ class BelongsToMany extends Association { ...@@ -724,7 +724,7 @@ class BelongsToMany extends Association {
if (association.scope) { if (association.scope) {
_.assign(values, association.scope); _.assign(values, association.scope);
if (options.fields) { if (options.fields) {
options.fields = options.fields.concat(Object.keys(association.scope)); Array.prototype.push.apply(options.fields, Object.keys(association.scope));
} }
} }
......
...@@ -252,7 +252,7 @@ class HasMany extends Association { ...@@ -252,7 +252,7 @@ class HasMany extends Association {
[ [
this.sequelize.fn( this.sequelize.fn(
'COUNT', 'COUNT',
this.sequelize.col(this.target.name.concat('.', this.target.primaryKeyField)) this.sequelize.col(`${this.target.name}.${this.target.primaryKeyField}`)
), ),
'count' 'count'
] ]
......
...@@ -59,10 +59,7 @@ function mixinMethods(association, obj, methods, aliases) { ...@@ -59,10 +59,7 @@ function mixinMethods(association, obj, methods, aliases) {
const realMethod = aliases[method] || method; const realMethod = aliases[method] || method;
obj[association.accessors[method]] = function() { obj[association.accessors[method]] = function() {
const instance = this; return association[realMethod].apply(association, [this, ...Array.from(arguments)]);
const args = [instance].concat(Array.from(arguments));
return association[realMethod].apply(association, args);
}; };
} }
} }
......
...@@ -99,7 +99,7 @@ const Hooks = { ...@@ -99,7 +99,7 @@ const Hooks = {
hooks = getHooks.call(this, hookType); hooks = getHooks.call(this, hookType);
if (this.sequelize) { if (this.sequelize) {
hooks = hooks.concat(getHooks.call(this.sequelize, hookType)); Array.prototype.push.apply(hooks, getHooks.call(this.sequelize, hookType));
} }
} }
......
...@@ -279,7 +279,7 @@ class InstanceValidator { ...@@ -279,7 +279,7 @@ class InstanceValidator {
const validatorArgs = this._extractValidatorArgs(test, validatorType, field); const validatorArgs = this._extractValidatorArgs(test, validatorType, field);
if (!validator[validatorType].apply(validator, [valueString].concat(validatorArgs))) { if (!validator[validatorType].apply(validator, [valueString, ...validatorArgs])) {
throw Object.assign(new Error(test.msg || `Validation ${validatorType} on ${field} failed`), { validatorName: validatorType, validatorArgs }); throw Object.assign(new Error(test.msg || `Validation ${validatorType} on ${field} failed`), { validatorName: validatorType, validatorArgs });
} }
}); });
......
...@@ -1690,9 +1690,9 @@ class Model { ...@@ -1690,9 +1690,9 @@ class Model {
if (options.include) { if (options.include) {
options.hasJoin = true; options.hasJoin = true;
this._validateIncludedElements(options, tableNames); this._validateIncludedElements(options, tableNames);
// If we're not raw, we have to make sure we include the primary key for de-duplication // If we're not raw, we have to make sure we include the primary key for de-duplication
if ( if (
options.attributes options.attributes
...@@ -1704,12 +1704,12 @@ class Model { ...@@ -1704,12 +1704,12 @@ class Model {
options.attributes = [this.primaryKeyAttribute].concat(options.attributes); options.attributes = [this.primaryKeyAttribute].concat(options.attributes);
} }
} }
if (!options.attributes) { if (!options.attributes) {
options.attributes = Object.keys(this.rawAttributes); options.attributes = Object.keys(this.rawAttributes);
options.originalAttributes = this._injectDependentVirtualAttributes(options.attributes); options.originalAttributes = this._injectDependentVirtualAttributes(options.attributes);
} }
// whereCollection is used for non-primary key updates // whereCollection is used for non-primary key updates
this.options.whereCollection = options.where || null; this.options.whereCollection = options.where || null;
...@@ -1777,9 +1777,9 @@ class Model { ...@@ -1777,9 +1777,9 @@ class Model {
attributes = attributes.concat(this.rawAttributes[attribute].type.fields); attributes = attributes.concat(this.rawAttributes[attribute].type.fields);
} }
} }
attributes = _.uniq(attributes); attributes = _.uniq(attributes);
return attributes; return attributes;
} }
...@@ -3040,11 +3040,11 @@ class Model { ...@@ -3040,11 +3040,11 @@ class Model {
if (options.attributes.exclude) { if (options.attributes.exclude) {
attributes = attributes.filter(elem => !options.attributes.exclude.includes(elem)); attributes = attributes.filter(elem => !options.attributes.exclude.includes(elem));
} }
if (options.attributes.include) { if (options.attributes.include) {
attributes = attributes.concat(options.attributes.include); attributes = attributes.concat(options.attributes.include);
} }
options.attributes = attributes; options.attributes = attributes;
} }
} }
......
...@@ -98,6 +98,7 @@ function format(sql, values, timeZone, dialect) { ...@@ -98,6 +98,7 @@ function format(sql, values, timeZone, dialect) {
if (typeof sql !== 'string') { if (typeof sql !== 'string') {
throw new Error('Invalid SQL string provided: ' + sql); throw new Error('Invalid SQL string provided: ' + sql);
} }
return sql.replace(/\?/g, match => { return sql.replace(/\?/g, match => {
if (!values.length) { if (!values.length) {
return match; return match;
......
...@@ -152,7 +152,7 @@ exports.cloneDeep = cloneDeep; ...@@ -152,7 +152,7 @@ exports.cloneDeep = cloneDeep;
function mapFinderOptions(options, Model) { function mapFinderOptions(options, Model) {
if (options.attributes && Array.isArray(options.attributes)) { if (options.attributes && Array.isArray(options.attributes)) {
options.attributes = Model._injectDependentVirtualAttributes(options.attributes); options.attributes = Model._injectDependentVirtualAttributes(options.attributes);
options.attributes = _.without.apply(_, [options.attributes].concat(Model._virtualAttributes)); options.attributes = _.without(options.attributes, ...Model._virtualAttributes);
} }
mapOptionFieldNames(options, Model); mapOptionFieldNames(options, Model);
......
...@@ -82,8 +82,7 @@ ...@@ -82,8 +82,7 @@
], ],
"main": "index", "main": "index",
"options": { "options": {
"env_cmd": "./test/config/.docker.env", "env_cmd": "./test/config/.docker.env"
"mocha": "--globals setImmediate,clearImmediate --ui tdd --exit --check-leaks --colors -t 30000 --reporter spec"
}, },
"scripts": { "scripts": {
"lint": "eslint lib test --quiet", "lint": "eslint lib test --quiet",
...@@ -93,14 +92,14 @@ ...@@ -93,14 +92,14 @@
"test-docker-integration": "env-cmd $npm_package_options_env_cmd npm run test-integration", "test-docker-integration": "env-cmd $npm_package_options_env_cmd npm run test-integration",
"docs": "esdoc && cp docs/ROUTER esdoc/ROUTER", "docs": "esdoc && cp docs/ROUTER esdoc/ROUTER",
"teaser": "node -e \"console.log('#'.repeat(process.env.DIALECT.length + 22) + '\\n# Running tests for ' + process.env.DIALECT + ' #\\n' + '#'.repeat(process.env.DIALECT.length + 22))\"", "teaser": "node -e \"console.log('#'.repeat(process.env.DIALECT.length + 22) + '\\n# Running tests for ' + process.env.DIALECT + ' #\\n' + '#'.repeat(process.env.DIALECT.length + 22))\"",
"test-unit": "mocha $npm_package_options_mocha \"test/unit/**/*.js\"", "test-unit": "mocha --require scripts/mocha-bootload --globals setImmediate,clearImmediate --ui tdd --exit --check-leaks --colors -t 30000 --reporter spec \"test/unit/**/*.js\"",
"test-unit-mysql": "cross-env DIALECT=mysql npm run test-unit", "test-unit-mysql": "cross-env DIALECT=mysql npm run test-unit",
"test-unit-postgres": "cross-env DIALECT=postgres npm run test-unit", "test-unit-postgres": "cross-env DIALECT=postgres npm run test-unit",
"test-unit-postgres-native": "cross-env DIALECT=postgres-native npm run test-unit", "test-unit-postgres-native": "cross-env DIALECT=postgres-native npm run test-unit",
"test-unit-sqlite": "cross-env DIALECT=sqlite npm run test-unit", "test-unit-sqlite": "cross-env DIALECT=sqlite npm run test-unit",
"test-unit-mssql": "cross-env DIALECT=mssql npm run test-unit", "test-unit-mssql": "cross-env DIALECT=mssql npm run test-unit",
"test-unit-all": "npm run test-unit-mysql && npm run test-unit-postgres && npm run test-unit-postgres-native && npm run test-unit-mssql && npm run test-unit-sqlite", "test-unit-all": "npm run test-unit-mysql && npm run test-unit-postgres && npm run test-unit-postgres-native && npm run test-unit-mssql && npm run test-unit-sqlite",
"test-integration": "mocha $npm_package_options_mocha \"test/integration/**/*.test.js\"", "test-integration": "mocha --require scripts/mocha-bootload --globals setImmediate,clearImmediate --ui tdd --exit --check-leaks --colors -t 30000 --reporter spec \"test/integration/**/*.test.js\"",
"test-integration-mysql": "cross-env DIALECT=mysql npm run test-integration", "test-integration-mysql": "cross-env DIALECT=mysql npm run test-integration",
"test-integration-postgres": "cross-env DIALECT=postgres npm run test-integration", "test-integration-postgres": "cross-env DIALECT=postgres npm run test-integration",
"test-integration-postgres-native": "cross-env DIALECT=postgres-native npm run test-integration", "test-integration-postgres-native": "cross-env DIALECT=postgres-native npm run test-integration",
...@@ -116,8 +115,8 @@ ...@@ -116,8 +115,8 @@
"test-mssql": "cross-env DIALECT=mssql npm test", "test-mssql": "cross-env DIALECT=mssql npm test",
"test-all": "npm run test-mysql && npm run test-sqlite && npm run test-postgres && npm run test-postgres-native && npm run test-mssql", "test-all": "npm run test-mysql && npm run test-sqlite && npm run test-postgres && npm run test-postgres-native && npm run test-mssql",
"cover": "rimraf coverage && npm run teaser && npm run cover-integration && npm run cover-unit && npm run merge-coverage", "cover": "rimraf coverage && npm run teaser && npm run cover-integration && npm run cover-unit && npm run merge-coverage",
"cover-integration": "cross-env COVERAGE=true ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -t 30000 --exit --ui tdd \"test/integration/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/integration.info')\"", "cover-integration": "cross-env COVERAGE=true ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --require scripts/mocha-bootload --report lcovonly -- -t 30000 --exit --ui tdd \"test/integration/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/integration.info')\"",
"cover-unit": "cross-env COVERAGE=true ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -t 30000 --exit --ui tdd \"test/unit/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/unit.info')\"", "cover-unit": "cross-env COVERAGE=true ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --require scripts/mocha-bootload --report lcovonly -- -t 30000 --exit --ui tdd \"test/unit/**/*.test.js\" && node -e \"require('fs').renameSync('coverage/lcov.info', 'coverage/unit.info')\"",
"merge-coverage": "lcov-result-merger \"coverage/*.info\" \"coverage/lcov.info\"", "merge-coverage": "lcov-result-merger \"coverage/*.info\" \"coverage/lcov.info\"",
"sscce": "env-cmd $npm_package_options_env_cmd node sscce.js", "sscce": "env-cmd $npm_package_options_env_cmd node sscce.js",
"sscce-mysql": "cross-env DIALECT=mysql npm run sscce", "sscce-mysql": "cross-env DIALECT=mysql npm run sscce",
......
require('any-promise/register/bluebird');
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!