Skip to content

Commit

Permalink
feat: optimize report saving (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjerci authored Mar 3, 2023
1 parent 7222310 commit 86cdb46
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
12 changes: 11 additions & 1 deletion new/detector/composition/javascript/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,21 @@ func New(rules map[string]*settings.Rule, classifier *classification.Classifier)
detectors = append(detectors, detector)
composition.closers = append(composition.closers, detector.Close)

presenceRules := map[string]bool{}
for _, rule := range jsRules {
if rule.TriggerRuleOnPresenceOf != "" {
presenceRules[rule.TriggerRuleOnPresenceOf] = true
}
}

for ruleName, rule := range jsRules {
patterns := rule.Patterns
localRuleName := ruleName

composition.customDetectorTypes = append(composition.customDetectorTypes, ruleName)
if !rule.IsAuxilary || presenceRules[ruleName] {
composition.customDetectorTypes = append(composition.customDetectorTypes, ruleName)
}

go func() {
customDetector, err := custom.New(
lang,
Expand Down
11 changes: 10 additions & 1 deletion new/detector/composition/ruby/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,20 @@ func New(rules map[string]*settings.Rule, classifier *classification.Classifier)
detectors = append(detectors, detector)
composition.closers = append(composition.closers, detector.Close)

presenceRules := map[string]bool{}
for _, rule := range rubyRules {
if rule.TriggerRuleOnPresenceOf != "" {
presenceRules[rule.TriggerRuleOnPresenceOf] = true
}
}

for ruleName, rule := range rubyRules {
patterns := rule.Patterns
localRuleName := ruleName

composition.customDetectorTypes = append(composition.customDetectorTypes, ruleName)
if !rule.IsAuxilary || presenceRules[ruleName] {
composition.customDetectorTypes = append(composition.customDetectorTypes, ruleName)
}

go func() {
customDetector, err := custom.New(
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/process/settings/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func buildRules(definitions map[string]RuleDefinition, enabledRules map[string]s
ParamParenting: auxiliaryDefinition.ParamParenting,
Patterns: auxiliaryDefinition.Patterns,
Stored: auxiliaryDefinition.Stored,
IsAuxilary: true,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/process/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type Rule struct {
Patterns []RulePattern `mapstructure:"patterns" json:"patterns" yaml:"patterns"`
DocumentationUrl string `mapstructure:"documentation_url" json:"documentation_url" yaml:"documentation_url"`
TriggerRuleOnPresenceOf string `mapstructure:"trigger_rule_on_presence_of" json:"trigger_rule_on_presence_of" yaml:"trigger_rule_on_presence_of"`
IsAuxilary bool `mapstructure:"is_auxilary" json:"is_auxilary" yaml:"is_auxilary"`

// FIXME: remove after refactor of sql
Metavars map[string]MetaVar `mapstructure:"metavars" json:"metavars" yaml:"metavars"`
Expand Down

0 comments on commit 86cdb46

Please sign in to comment.