From 45fa1c4498960a3ed8f7317cd0b49c7ae9ac188d Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Fri, 19 Aug 2022 12:37:53 +0300 Subject: [PATCH] Fix intersection of search results --- restream/restream.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/restream/restream.go b/restream/restream.go index 137e0acb..50577bc6 100644 --- a/restream/restream.go +++ b/restream/restream.go @@ -826,6 +826,7 @@ func (r *restream) GetProcessIDs(idpattern, refpattern string) []string { } idmap := map[string]int{} + count := 0 if len(idpattern) != 0 { for id := range r.tasks { @@ -838,8 +839,10 @@ func (r *restream) GetProcessIDs(idpattern, refpattern string) []string { continue } - idmap[id] = 1 + idmap[id]++ } + + count++ } if len(refpattern) != 0 { @@ -853,22 +856,20 @@ func (r *restream) GetProcessIDs(idpattern, refpattern string) []string { continue } - if _, ok := idmap[t.id]; ok { - idmap[t.id]++ - } + idmap[t.id]++ } + + count++ } - ids := make([]string, len(idmap)) - i := 0 + ids := []string{} - for id, count := range idmap { - if count == 1 { + for id, n := range idmap { + if n != count { continue } - ids[i] = id - i++ + ids = append(ids, id) } return ids