UNPKG

@abaplint/core

Version:
67 lines 2.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.IndexCompletelyContained = exports.IndexCompletelyContainedConf = void 0; const _basic_rule_config_1 = require("./_basic_rule_config"); const _irule_1 = require("./_irule"); const issue_1 = require("../issue"); const position_1 = require("../position"); const Objects = require("../objects"); class IndexCompletelyContainedConf extends _basic_rule_config_1.BasicRuleConfig { } exports.IndexCompletelyContainedConf = IndexCompletelyContainedConf; class IndexCompletelyContained { constructor() { this.conf = new IndexCompletelyContainedConf(); } getMetadata() { return { key: "index_completely_contained", title: "Check if database table indexes are completely contained", shortDescription: `If indexes are completely contained in other indexes, they can be removed to improve performance.`, tags: [_irule_1.RuleTag.Performance, _irule_1.RuleTag.SingleFile], }; } initialize() { return this; } getConfig() { return this.conf; } setConfig(conf) { this.conf = conf; } run(obj) { if (!(obj instanceof Objects.Table)) { return []; } const indexes = obj.getSecondaryIndexes(); if (indexes === undefined || indexes.length === 0) { return []; } const issues = []; for (let i = 0; i < indexes.length; i++) { const indexA = indexes[i]; for (let j = 0; j < indexes.length; j++) { if (i === j) { continue; } const indexB = indexes[j]; let contained = true; for (const field of indexA.fields) { if (indexB.fields.indexOf(field) === -1) { contained = false; break; } } if (contained) { const position = new position_1.Position(1, 1); const message = `Index "${indexA.name}" is completely contained in index "${indexB.name}"`; issues.push(issue_1.Issue.atPosition(obj.getFiles()[0], position, message, this.getMetadata().key, this.conf.severity)); } } } return issues; } } exports.IndexCompletelyContained = IndexCompletelyContained; //# sourceMappingURL=index_completely_contained.js.map