From 59ed7165e132b0adec16ba06190ec7dbb872d010 Mon Sep 17 00:00:00 2001 From: Raymond Date: Wed, 19 Oct 2022 15:27:58 +0200 Subject: [PATCH 1/3] Remove deleted repos from searchresult This prevents a 500 result, because null pointer exceptions in rendering the template. This happends bc the repoId is not in the repoMap because it is delete (or archived?) --- routers/web/explore/code.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index 2357b34fd0caf..cc60cd37ad53a 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -110,6 +110,16 @@ func Code(ctx *context.Context) { } ctx.Data["RepoMaps"] = repoMaps + + //Remove deleted repos from search results + var cleanedSearchResults = make([]*code_indexer.Result, 0, len(repoMaps)) + for _, sr := range searchResults { + if _, found := repoMaps[sr.RepoID]; found { + cleanedSearchResults = append(cleanedSearchResults, sr) + } + } + + searchResults = cleanedSearchResults } ctx.Data["SearchResults"] = searchResults From 97bc49eb937c7792c2497eb4d33f8e73e96bdaab Mon Sep 17 00:00:00 2001 From: Raymond Kroon Date: Wed, 19 Oct 2022 15:50:55 +0200 Subject: [PATCH 2/3] fmt code --- routers/web/explore/code.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index cc60cd37ad53a..a2cb185b8189f 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -111,8 +111,8 @@ func Code(ctx *context.Context) { ctx.Data["RepoMaps"] = repoMaps - //Remove deleted repos from search results - var cleanedSearchResults = make([]*code_indexer.Result, 0, len(repoMaps)) + // Remove deleted repos from search results + cleanedSearchResults := make([]*code_indexer.Result, 0, len(repoMaps)) for _, sr := range searchResults { if _, found := repoMaps[sr.RepoID]; found { cleanedSearchResults = append(cleanedSearchResults, sr) From 5eb5c3af66aee12755df355847e2384dfc492690 Mon Sep 17 00:00:00 2001 From: Raymond Kroon Date: Thu, 20 Oct 2022 08:55:34 +0200 Subject: [PATCH 3/3] only check for delete repos when len() is different --- routers/web/explore/code.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index a2cb185b8189f..38474255d19ba 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -111,15 +111,17 @@ func Code(ctx *context.Context) { ctx.Data["RepoMaps"] = repoMaps - // Remove deleted repos from search results - cleanedSearchResults := make([]*code_indexer.Result, 0, len(repoMaps)) - for _, sr := range searchResults { - if _, found := repoMaps[sr.RepoID]; found { - cleanedSearchResults = append(cleanedSearchResults, sr) + if len(loadRepoIDs) != len(repoMaps) { + // Remove deleted repos from search results + cleanedSearchResults := make([]*code_indexer.Result, 0, len(repoMaps)) + for _, sr := range searchResults { + if _, found := repoMaps[sr.RepoID]; found { + cleanedSearchResults = append(cleanedSearchResults, sr) + } } - } - searchResults = cleanedSearchResults + searchResults = cleanedSearchResults + } } ctx.Data["SearchResults"] = searchResults