Skip to content

Commit 24249ab

Browse files
committed
code cleanup
1 parent fdcc0b6 commit 24249ab

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

.golangci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ issues:
9696
- "cognitive complexity .* of func `.*..optimizeStatsGroups` is high"
9797
- "cognitive complexity .* of func `.*Peer..waitcondition` is high"
9898
- "cognitive complexity .* of func `.*Request..getDistributedResponse` is high"
99-
- "cognitive complexity .* of func `appendIndexHostsFromServiceColumns` is high"
99+
- "cognitive complexity .* of func `.*appendIndexHostsFromServiceColumns` is high"
100100
- "cognitive complexity .* of func `ProcessRequests` is high"
101101
- "cognitive complexity .* of func `prepareTmpDataHostService` is high"
102102
- "cognitive complexity .* of func `.*RawResultSet..Less` is high"
@@ -105,7 +105,7 @@ issues:
105105
- "cyclomatic complexity .* of func `.*Less` is high"
106106
- "cyclomatic complexity .* of func `.*ParseRequestHeaderLine` is high"
107107
- "cyclomatic complexity .* of func `.*String` is high"
108-
- "cyclomatic complexity .* of func `appendIndexHostsFromServiceColumns` is high"
108+
- "cyclomatic complexity .* of func `.*appendIndexHostsFromServiceColumns` is high"
109109
- "cyclomatic complexity .* of func `matchStringListFilter` is high"
110110
- "cyclomatic complexity .* of func `TestNegate` is high"
111111
- "cyclomatic complexity .* of func `TestNodeManager` is high"

pkg/lmd/datastore.go

+21-21
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func (d *DataStore) GetWaitObject(req *Request) (*DataRow, bool) {
264264
return obj, ok
265265
}
266266

267-
type getPreFilteredDataFilter func(*DataStore, map[string]bool, *Filter) bool
267+
type getPreFilteredDataFilter func(map[string]bool, *Filter) bool
268268

269269
// GetPreFilteredData returns d.Data but try to return reduced dataset by using host / service index if table supports it.
270270
func (d *DataStore) GetPreFilteredData(filter []*Filter) []*DataRow {
@@ -274,11 +274,11 @@ func (d *DataStore) GetPreFilteredData(filter []*Filter) []*DataRow {
274274

275275
switch {
276276
case d.Table.Name == TableHosts:
277-
return (d.tryFilterIndexData(filter, appendIndexHostsFromHostColumns))
277+
return (d.tryFilterIndexData(filter, d.appendIndexHostsFromHostColumns))
278278
case d.Table.Name == TableServices:
279-
return (d.tryFilterIndexData(filter, appendIndexHostsFromServiceColumns))
279+
return (d.tryFilterIndexData(filter, d.appendIndexHostsFromServiceColumns))
280280
case len(d.Table.PrimaryKey) == 1:
281-
return (d.tryFilterIndexData(filter, appendIndexFromPrimaryKey))
281+
return (d.tryFilterIndexData(filter, d.appendIndexFromPrimaryKey))
282282
default:
283283
// only hosts and services are supported
284284
}
@@ -462,7 +462,7 @@ func (d *DataStore) TryFilterIndex(uniqHosts map[string]bool, filter []*Filter,
462462
}
463463
filterFound++
464464
default:
465-
if filterCb(d, uniqHosts, fil) {
465+
if filterCb(uniqHosts, fil) {
466466
filterFound++
467467
} else if breakOnNoneIndexableFilter {
468468
return false
@@ -474,7 +474,7 @@ func (d *DataStore) TryFilterIndex(uniqHosts map[string]bool, filter []*Filter,
474474
return filterFound > 0
475475
}
476476

477-
func appendIndexHostsFromHostColumns(dStore *DataStore, uniqHosts map[string]bool, fil *Filter) bool {
477+
func (d *DataStore) appendIndexHostsFromHostColumns(uniqHosts map[string]bool, fil *Filter) bool {
478478
switch fil.Column.Name {
479479
case "name":
480480
switch fil.Operator {
@@ -487,7 +487,7 @@ func appendIndexHostsFromHostColumns(dStore *DataStore, uniqHosts map[string]boo
487487
// name =~ <value>
488488
case EqualNocase:
489489
uniqHosts[fil.StrValue] = true
490-
for _, key := range dStore.IndexLowerCase[strings.ToLower(fil.StrValue)] {
490+
for _, key := range d.IndexLowerCase[strings.ToLower(fil.StrValue)] {
491491
uniqHosts[key] = true
492492
}
493493

@@ -500,7 +500,7 @@ func appendIndexHostsFromHostColumns(dStore *DataStore, uniqHosts map[string]boo
500500
// name == <value>
501501
case Equal, EqualNocase:
502502
uniqHosts[fil.StrValue] = true
503-
for _, key := range dStore.IndexLowerCase[strings.ToLower(fil.StrValue)] {
503+
for _, key := range d.IndexLowerCase[strings.ToLower(fil.StrValue)] {
504504
uniqHosts[key] = true
505505
}
506506

@@ -513,7 +513,7 @@ func appendIndexHostsFromHostColumns(dStore *DataStore, uniqHosts map[string]boo
513513
switch fil.Operator {
514514
// groups >= <value>
515515
case GreaterThan:
516-
store := dStore.DataSet.tables[TableHostgroups]
516+
store := d.DataSet.tables[TableHostgroups]
517517
group, ok := store.Index[fil.StrValue]
518518
if ok {
519519
members := group.GetStringListByName("members")
@@ -524,7 +524,7 @@ func appendIndexHostsFromHostColumns(dStore *DataStore, uniqHosts map[string]boo
524524

525525
return true
526526
case RegexMatch, RegexNoCaseMatch, Contains, ContainsNoCase:
527-
store := dStore.DataSet.tables[TableHostgroups]
527+
store := d.DataSet.tables[TableHostgroups]
528528
for groupname, group := range store.Index {
529529
if fil.MatchString(strings.ToLower(groupname)) {
530530
members := group.GetStringListByName("members")
@@ -543,7 +543,7 @@ func appendIndexHostsFromHostColumns(dStore *DataStore, uniqHosts map[string]boo
543543
return false
544544
}
545545

546-
func appendIndexHostsFromServiceColumns(dStore *DataStore, uniqHosts map[string]bool, fil *Filter) bool {
546+
func (d *DataStore) appendIndexHostsFromServiceColumns(uniqHosts map[string]bool, fil *Filter) bool {
547547
switch fil.Column.Name {
548548
case "host_name":
549549
switch fil.Operator {
@@ -554,7 +554,7 @@ func appendIndexHostsFromServiceColumns(dStore *DataStore, uniqHosts map[string]
554554
return true
555555
// host_name ~ <value>
556556
case RegexMatch, Contains:
557-
store := dStore.DataSet.tables[TableHosts]
557+
store := d.DataSet.tables[TableHosts]
558558
for hostname := range store.Index {
559559
if fil.MatchString(hostname) {
560560
uniqHosts[hostname] = true
@@ -569,7 +569,7 @@ func appendIndexHostsFromServiceColumns(dStore *DataStore, uniqHosts map[string]
569569
switch fil.Operator {
570570
// host_name ~~ <value>
571571
case RegexMatch, Contains, RegexNoCaseMatch, ContainsNoCase, EqualNocase, Equal:
572-
store := dStore.DataSet.tables[TableHosts]
572+
store := d.DataSet.tables[TableHosts]
573573
for hostname := range store.Index {
574574
if fil.MatchString(strings.ToLower(hostname)) {
575575
uniqHosts[hostname] = true
@@ -585,7 +585,7 @@ func appendIndexHostsFromServiceColumns(dStore *DataStore, uniqHosts map[string]
585585
switch fil.Operator {
586586
// groups >= <value>
587587
case GreaterThan:
588-
store := dStore.DataSet.tables[TableHostgroups]
588+
store := d.DataSet.tables[TableHostgroups]
589589
group, ok := store.Index[fil.StrValue]
590590
if ok {
591591
members := group.GetStringListByName("members")
@@ -596,7 +596,7 @@ func appendIndexHostsFromServiceColumns(dStore *DataStore, uniqHosts map[string]
596596

597597
return true
598598
case RegexMatch, RegexNoCaseMatch, Contains, ContainsNoCase:
599-
store := dStore.DataSet.tables[TableHostgroups]
599+
store := d.DataSet.tables[TableHostgroups]
600600
for groupname, group := range store.Index {
601601
if fil.MatchString(strings.ToLower(groupname)) {
602602
members := group.GetStringListByName("members")
@@ -615,7 +615,7 @@ func appendIndexHostsFromServiceColumns(dStore *DataStore, uniqHosts map[string]
615615
switch fil.Operator {
616616
// groups >= <value>
617617
case GreaterThan:
618-
store := dStore.DataSet.tables[TableServicegroups]
618+
store := d.DataSet.tables[TableServicegroups]
619619
group, ok := store.Index[fil.StrValue]
620620
if ok {
621621
members := group.GetServiceMemberListByName("members")
@@ -626,7 +626,7 @@ func appendIndexHostsFromServiceColumns(dStore *DataStore, uniqHosts map[string]
626626

627627
return true
628628
case RegexMatch, RegexNoCaseMatch, Contains, ContainsNoCase:
629-
store := dStore.DataSet.tables[TableServicegroups]
629+
store := d.DataSet.tables[TableServicegroups]
630630
for groupname, group := range store.Index {
631631
if fil.MatchString(groupname) {
632632
members := group.GetServiceMemberListByName("members")
@@ -647,8 +647,8 @@ func appendIndexHostsFromServiceColumns(dStore *DataStore, uniqHosts map[string]
647647
return false
648648
}
649649

650-
func appendIndexFromPrimaryKey(dStore *DataStore, uniqRows map[string]bool, fil *Filter) bool {
651-
key := dStore.Table.PrimaryKey[0]
650+
func (d *DataStore) appendIndexFromPrimaryKey(uniqRows map[string]bool, fil *Filter) bool {
651+
key := d.Table.PrimaryKey[0]
652652

653653
switch fil.Column.Name {
654654
case key:
@@ -662,7 +662,7 @@ func appendIndexFromPrimaryKey(dStore *DataStore, uniqRows map[string]bool, fil
662662
// name =~ <value>
663663
case EqualNocase:
664664
uniqRows[fil.StrValue] = true
665-
for _, key := range dStore.IndexLowerCase[strings.ToLower(fil.StrValue)] {
665+
for _, key := range d.IndexLowerCase[strings.ToLower(fil.StrValue)] {
666666
uniqRows[key] = true
667667
}
668668

@@ -675,7 +675,7 @@ func appendIndexFromPrimaryKey(dStore *DataStore, uniqRows map[string]bool, fil
675675
// name == <value>
676676
case Equal, EqualNocase:
677677
uniqRows[fil.StrValue] = true
678-
for _, key := range dStore.IndexLowerCase[strings.ToLower(fil.StrValue)] {
678+
for _, key := range d.IndexLowerCase[strings.ToLower(fil.StrValue)] {
679679
uniqRows[key] = true
680680
}
681681

0 commit comments

Comments
 (0)