mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 14:56:01 +00:00
lodash optimalization
This commit is contained in:
@@ -2,7 +2,7 @@ import { DatabaseInfo, DatabaseModification, EngineDriver } from 'dbgate-types';
|
|||||||
import _sortBy from 'lodash/sortBy';
|
import _sortBy from 'lodash/sortBy';
|
||||||
import _groupBy from 'lodash/groupBy';
|
import _groupBy from 'lodash/groupBy';
|
||||||
import _pick from 'lodash/pick';
|
import _pick from 'lodash/pick';
|
||||||
import _ from 'lodash';
|
import _compact from 'lodash/compact';
|
||||||
|
|
||||||
const fp_pick = arg => array => _pick(array, arg);
|
const fp_pick = arg => array => _pick(array, arg);
|
||||||
export class DatabaseAnalyser {
|
export class DatabaseAnalyser {
|
||||||
@@ -134,7 +134,7 @@ export class DatabaseAnalyser {
|
|||||||
return this.structure[objectTypeField]
|
return this.structure[objectTypeField]
|
||||||
.filter(x => !items.find(y => x.objectId == y.objectId))
|
.filter(x => !items.find(y => x.objectId == y.objectId))
|
||||||
.map(x => ({
|
.map(x => ({
|
||||||
oldName: _.pick(x, ['schemaName', 'pureName']),
|
oldName: _pick(x, ['schemaName', 'pureName']),
|
||||||
objectId: x.objectId,
|
objectId: x.objectId,
|
||||||
action: 'remove',
|
action: 'remove',
|
||||||
objectTypeField,
|
objectTypeField,
|
||||||
@@ -175,7 +175,7 @@ export class DatabaseAnalyser {
|
|||||||
const action = obj
|
const action = obj
|
||||||
? {
|
? {
|
||||||
newName: { schemaName, pureName },
|
newName: { schemaName, pureName },
|
||||||
oldName: _.pick(obj, ['schemaName', 'pureName']),
|
oldName: _pick(obj, ['schemaName', 'pureName']),
|
||||||
action: 'change',
|
action: 'change',
|
||||||
objectTypeField: field,
|
objectTypeField: field,
|
||||||
objectId,
|
objectId,
|
||||||
@@ -189,7 +189,7 @@ export class DatabaseAnalyser {
|
|||||||
res.push(action);
|
res.push(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [..._.compact(res), ...this.getDeletedObjects(snapshot)];
|
return [..._compact(res), ...this.getDeletedObjects(snapshot)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import {
|
|||||||
TriggerInfo,
|
TriggerInfo,
|
||||||
ViewInfo,
|
ViewInfo,
|
||||||
} from 'dbgate-types';
|
} from 'dbgate-types';
|
||||||
import _ from 'lodash';
|
import _flatten from 'lodash/flatten';
|
||||||
|
import _uniqBy from 'lodash/uniqBy'
|
||||||
import { SqlDumper } from './SqlDumper';
|
import { SqlDumper } from './SqlDumper';
|
||||||
import { extendDatabaseInfo } from './structureTools';
|
import { extendDatabaseInfo } from './structureTools';
|
||||||
|
|
||||||
@@ -122,9 +123,9 @@ export class SqlGenerator {
|
|||||||
|
|
||||||
createForeignKeys() {
|
createForeignKeys() {
|
||||||
const fks = [];
|
const fks = [];
|
||||||
if (this.options.createForeignKeys) fks.push(..._.flatten(this.tables.map(x => x.foreignKeys || [])));
|
if (this.options.createForeignKeys) fks.push(..._flatten(this.tables.map(x => x.foreignKeys || [])));
|
||||||
if (this.options.createReferences) fks.push(..._.flatten(this.tables.map(x => x.dependencies || [])));
|
if (this.options.createReferences) fks.push(..._flatten(this.tables.map(x => x.dependencies || [])));
|
||||||
for (const fk of _.uniqBy(fks, 'constraintName')) {
|
for (const fk of _uniqBy(fks, 'constraintName')) {
|
||||||
this.dmp.createForeignKey(fk);
|
this.dmp.createForeignKey(fk);
|
||||||
if (this.checkDumper()) return;
|
if (this.checkDumper()) return;
|
||||||
}
|
}
|
||||||
@@ -152,7 +153,7 @@ export class SqlGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.options.createIndexes) {
|
if (this.options.createIndexes) {
|
||||||
for (const index of _.flatten(this.tables.map(x => x.indexes || []))) {
|
for (const index of _flatten(this.tables.map(x => x.indexes || []))) {
|
||||||
this.dmp.createIndex(index);
|
this.dmp.createIndex(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,7 +205,7 @@ export class SqlGenerator {
|
|||||||
|
|
||||||
dropTables() {
|
dropTables() {
|
||||||
if (this.options.dropReferences) {
|
if (this.options.dropReferences) {
|
||||||
for (const fk of _.flatten(this.tables.map(x => x.dependencies || []))) {
|
for (const fk of _flatten(this.tables.map(x => x.dependencies || []))) {
|
||||||
this.dmp.dropForeignKey(fk);
|
this.dmp.dropForeignKey(fk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import _ from 'lodash';
|
import _isNaN from 'lodash/isNaN';
|
||||||
|
import _isNumber from 'lodash/isNumber';
|
||||||
|
|
||||||
export function extractIntSettingsValue(settings, name, defaultValue, min = null, max = null) {
|
export function extractIntSettingsValue(settings, name, defaultValue, min = null, max = null) {
|
||||||
const parsed = parseInt(settings[name]);
|
const parsed = parseInt(settings[name]);
|
||||||
if (_.isNaN(parsed)) {
|
if (_isNaN(parsed)) {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
if (_.isNumber(parsed)) {
|
if (_isNumber(parsed)) {
|
||||||
if (min != null && parsed < min) return min;
|
if (min != null && parsed < min) return min;
|
||||||
if (max != null && parsed > max) return max;
|
if (max != null && parsed > max) return max;
|
||||||
return parsed;
|
return parsed;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { DatabaseInfo } from 'dbgate-types';
|
import { DatabaseInfo } from 'dbgate-types';
|
||||||
import _ from 'lodash';
|
import _flatten from 'lodash/flatten';
|
||||||
|
|
||||||
export function addTableDependencies(db: DatabaseInfo): DatabaseInfo {
|
export function addTableDependencies(db: DatabaseInfo): DatabaseInfo {
|
||||||
const allForeignKeys = _.flatten(db.tables.map(x => x.foreignKeys || []));
|
const allForeignKeys = _flatten(db.tables.map(x => x.foreignKeys || []));
|
||||||
return {
|
return {
|
||||||
...db,
|
...db,
|
||||||
tables: db.tables.map(table => ({
|
tables: db.tables.map(table => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user