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

Commit 09dcaca3 by Sushant Committed by GitHub

perf: some improvements / cleanup (#9576)

1 parent 2c50b7ee
......@@ -2,6 +2,7 @@ docs
esdoc
examples
test
scripts
README.md
.watchr.js
changelog.md
......
......@@ -24,7 +24,7 @@ install:
build: off
before_test:
- ps: . .\appveyor-setup.ps1
- ps: . .\scripts\appveyor-setup.ps1
test_script:
- 'IF "%COVERAGE%" == "true" (npm run cover) ELSE (npm test)'
......
......@@ -724,7 +724,7 @@ class BelongsToMany extends Association {
if (association.scope) {
_.assign(values, association.scope);
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 {
[
this.sequelize.fn(
'COUNT',
this.sequelize.col(this.target.name.concat('.', this.target.primaryKeyField))
this.sequelize.col(`${this.target.name}.${this.target.primaryKeyField}`)
),
'count'
]
......
......@@ -59,10 +59,7 @@ function mixinMethods(association, obj, methods, aliases) {
const realMethod = aliases[method] || method;
obj[association.accessors[method]] = function() {
const instance = this;
const args = [instance].concat(Array.from(arguments));
return association[realMethod].apply(association, args);
return association[realMethod].apply(association, [this, ...Array.from(arguments)]);
};
}
}
......
......@@ -99,7 +99,7 @@ const Hooks = {
hooks = getHooks.call(this, hookType);
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 {
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 });
}
});
......
......@@ -1690,9 +1690,9 @@ class Model {
if (options.include) {
options.hasJoin = true;
this._validateIncludedElements(options, tableNames);
// If we're not raw, we have to make sure we include the primary key for de-duplication
if (
options.attributes
......@@ -1704,12 +1704,12 @@ class Model {
options.attributes = [this.primaryKeyAttribute].concat(options.attributes);
}
}
if (!options.attributes) {
options.attributes = Object.keys(this.rawAttributes);
options.originalAttributes = this._injectDependentVirtualAttributes(options.attributes);
}
// whereCollection is used for non-primary key updates
this.options.whereCollection = options.where || null;
......@@ -1777,9 +1777,9 @@ class Model {
attributes = attributes.concat(this.rawAttributes[attribute].type.fields);
}
}
attributes = _.uniq(attributes);
return attributes;
}
......@@ -3040,11 +3040,11 @@ class Model {
if (options.attributes.exclude) {
attributes = attributes.filter(elem => !options.attributes.exclude.includes(elem));
}
if (options.attributes.include) {
attributes = attributes.concat(options.attributes.include);
}
options.attributes = attributes;
}
}
......
......@@ -98,6 +98,7 @@ function format(sql, values, timeZone, dialect) {
if (typeof sql !== 'string') {
throw new Error('Invalid SQL string provided: ' + sql);
}
return sql.replace(/\?/g, match => {
if (!values.length) {
return match;
......
......@@ -152,7 +152,7 @@ exports.cloneDeep = cloneDeep;
function mapFinderOptions(options, Model) {
if (options.attributes && Array.isArray(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);
......
......@@ -82,8 +82,7 @@
],
"main": "index",
"options": {
"env_cmd": "./test/config/.docker.env",
"mocha": "--globals setImmediate,clearImmediate --ui tdd --exit --check-leaks --colors -t 30000 --reporter spec"
"env_cmd": "./test/config/.docker.env"
},
"scripts": {
"lint": "eslint lib test --quiet",
......@@ -93,14 +92,14 @@
"test-docker-integration": "env-cmd $npm_package_options_env_cmd npm run test-integration",
"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))\"",
"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-postgres": "cross-env DIALECT=postgres 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-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-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-postgres": "cross-env DIALECT=postgres npm run test-integration",
"test-integration-postgres-native": "cross-env DIALECT=postgres-native npm run test-integration",
......@@ -116,8 +115,8 @@
"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",
"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-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-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 --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\"",
"sscce": "env-cmd $npm_package_options_env_cmd node sscce.js",
"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!