From 682da55271b92deb148438450284403feaa21dcc Mon Sep 17 00:00:00 2001 From: Amine Hilaly Date: Thu, 4 Apr 2019 12:58:20 +0200 Subject: [PATCH] Improve actor/participant query filters Lower case identity login --- cache/filter.go | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/cache/filter.go b/cache/filter.go index 48ee66782ed3e2a12878b740fa3b891f73b7a3b2..7b1a60545c6c1bcf3e9f4817e71d66ab08d97229 100644 --- a/cache/filter.go +++ b/cache/filter.go @@ -56,35 +56,43 @@ func LabelFilter(label string) Filter { } // ActorFilter return a Filter that match a bug actor -func ActorFilter(actor string) Filter { +func ActorFilter(query string) Filter { return func(repoCache *RepoCache, excerpt *BugExcerpt) bool { - for _, identityExcerpt := range repoCache.identitiesExcerpts { - if strings.Contains(strings.ToLower(identityExcerpt.Name), actor) || - actor == identityExcerpt.Id || actor == identityExcerpt.Login { - for _, actorId := range excerpt.Actors { - if identityExcerpt.Id == actorId { - return true - } - } + query = strings.ToLower(query) + + for _, id := range excerpt.Actors { + identityExcerpt, ok := repoCache.identitiesExcerpts[id] + if !ok { + panic("missing identity in the cache") + } + + if strings.Contains(strings.ToLower(identityExcerpt.Name), query) || + query == identityExcerpt.Id || query == strings.ToLower(identityExcerpt.Login) { + return true } } + return false } } // ParticipantFilter return a Filter that match a bug participant -func ParticipantFilter(participant string) Filter { +func ParticipantFilter(query string) Filter { return func(repoCache *RepoCache, excerpt *BugExcerpt) bool { - for _, identityExcerpt := range repoCache.identitiesExcerpts { - if strings.Contains(strings.ToLower(identityExcerpt.Name), participant) || - participant == identityExcerpt.Id || participant == identityExcerpt.Login { - for _, participantId := range excerpt.Participants { - if identityExcerpt.Id == participantId { - return true - } - } + query = strings.ToLower(query) + + for _, id := range excerpt.Participants { + identityExcerpt, ok := repoCache.identitiesExcerpts[id] + if !ok { + panic("missing identity in the cache") + } + + if strings.Contains(strings.ToLower(identityExcerpt.Name), query) || + query == identityExcerpt.Id || query == strings.ToLower(identityExcerpt.Login) { + return true } } + return false } }