diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-03-01 22:26:31 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-03-01 22:26:31 +0300 |
commit | 62efe96a37a1eaf1a30a52ca56571295da2073db (patch) | |
tree | 037f4bf28774fe0392fdc6f50bdbd30c21995466 | |
parent | acdb4147d57ac1517363f8b1455ee06cce2dfc8f (diff) | |
parent | 09921287b8d55ae0adcf52ed75ddfe0d25427564 (diff) |
Merge branch 'jc-remove-search-files-non-chunked' into 'master'
Remove non-chunked code path for SearchFilesByContent
Closes #1464
See merge request gitlab-org/gitaly!1100
-rw-r--r-- | changelogs/unreleased/jc-remove-search-files-non-chunked.yml | 5 | ||||
-rw-r--r-- | internal/service/repository/search_files.go | 54 | ||||
-rw-r--r-- | internal/service/repository/search_files_test.go | 29 |
3 files changed, 8 insertions, 80 deletions
diff --git a/changelogs/unreleased/jc-remove-search-files-non-chunked.yml b/changelogs/unreleased/jc-remove-search-files-non-chunked.yml new file mode 100644 index 000000000..d9fac6427 --- /dev/null +++ b/changelogs/unreleased/jc-remove-search-files-non-chunked.yml @@ -0,0 +1,5 @@ +--- +title: Remove non-chunked code path for SearchFilesByContent +merge_request: 1100 +author: +type: other diff --git a/internal/service/repository/search_files.go b/internal/service/repository/search_files.go index a69ce913b..31a9f8efa 100644 --- a/internal/service/repository/search_files.go +++ b/internal/service/repository/search_files.go @@ -48,58 +48,8 @@ func (s *server) SearchFilesByContent(req *gitalypb.SearchFilesByContentRequest, return status.Errorf(codes.Internal, "SearchFilesByContent: cmd start failed: %v", err) } - if req.GetChunkedResponse() { - if err = sendSearchFilesResultChunked(cmd, stream); err != nil { - return status.Errorf(codes.Internal, "SearchFilesByContent: sending chunked response failed: %v", err) - } - return nil - } - - // Deprecated: we will remove this code path once all clients begin using chunked responses post 11.8 - if err = sendSearchFilesResult(cmd, stream); err != nil { - return status.Errorf(codes.Internal, "SearchFilesByContent: sending response failed: %v", err) - } - - return nil -} - -// Deprecated: we will remove this code path once all clients begin using chunked responses post 11.8 -func sendSearchFilesResult(cmd *command.Command, stream gitalypb.RepositoryService_SearchFilesByContentServer) error { - var ( - err error - buf []byte - matches [][]byte - ) - - reader := func(objs [][]byte) error { - for _, obj := range objs { - obj = append(obj, '\n') - if bytes.Equal(obj, contentDelimiter) { - matches = append(matches, buf) - buf = nil - } else { - buf = append(buf, obj...) - } - } - if len(matches) > 0 { - err = stream.Send(&gitalypb.SearchFilesByContentResponse{Matches: matches}) - matches = nil - return err - } - return nil - } - - err = lines.Send(cmd, reader, []byte{'\n'}) - if err != nil { - return helper.DecorateError(codes.Internal, err) - } - - if len(buf) > 0 { - matches = append(matches, buf) - } - - if len(matches) > 0 { - return stream.Send(&gitalypb.SearchFilesByContentResponse{Matches: matches}) + if err = sendSearchFilesResultChunked(cmd, stream); err != nil { + return status.Errorf(codes.Internal, "SearchFilesByContent: sending chunked response failed: %v", err) } return nil diff --git a/internal/service/repository/search_files_test.go b/internal/service/repository/search_files_test.go index e8e201101..28ea0f203 100644 --- a/internal/service/repository/search_files_test.go +++ b/internal/service/repository/search_files_test.go @@ -137,17 +137,6 @@ func TestSearchFilesByContentSuccessful(t *testing.T) { for i := 0; i < len(tc.output); i++ { require.Equal(t, tc.output[i], resp[i]) } - // Deprecated: testing the old non-chunking code path until we remove it post 11.8 - request.ChunkedResponse = false - stream, err = client.SearchFilesByContent(ctx, request) - require.NoError(t, err) - - resp, err = consumeFilenameByContent(stream) - require.NoError(t, err) - require.Equal(t, len(tc.output), len(resp)) - for i := 0; i < len(tc.output); i++ { - require.Equal(t, tc.output[i], resp[i]) - } }) } } @@ -260,7 +249,7 @@ func TestSearchFilesByContentFailure(t *testing.T) { }) require.NoError(t, err) - _, err = consumeFilenameByContent(stream) + _, err = consumeFilenameByContentChunked(stream) testhelper.RequireGrpcError(t, err, tc.code) require.Contains(t, err.Error(), tc.msg) }) @@ -372,22 +361,6 @@ func TestSearchFilesByNameFailure(t *testing.T) { } } -func consumeFilenameByContent(stream gitalypb.RepositoryService_SearchFilesByContentClient) ([][]byte, error) { - var ret [][]byte - for done := false; !done; { - resp, err := stream.Recv() - if err == io.EOF { - break - } - if err != nil { - return nil, err - } - ret = append(ret, resp.Matches...) - } - return ret, nil - -} - func consumeFilenameByContentChunked(stream gitalypb.RepositoryService_SearchFilesByContentClient) ([][]byte, error) { var ret [][]byte var match []byte |