diff options
author | Jacob Vosmaer (GitLab) <jacob@gitlab.com> | 2018-07-06 21:22:43 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2018-07-12 14:39:42 +0300 |
commit | a44fd5e281d51195133c13f9605129d078c6bf91 (patch) | |
tree | 17eee47927267576484235ee93a6d675abbaa5aa | |
parent | 0a1f87eb11c93fe71cd0fd3da0c70434a29ee57b (diff) |
Remove unnecessary commit size calculations
-rw-r--r-- | changelogs/unreleased/fix-commit-size-nil-panic.yml | 5 | ||||
-rw-r--r-- | internal/service/commit/commits_helper.go | 14 | ||||
-rw-r--r-- | internal/service/commit/server.go | 1 |
3 files changed, 8 insertions, 12 deletions
diff --git a/changelogs/unreleased/fix-commit-size-nil-panic.yml b/changelogs/unreleased/fix-commit-size-nil-panic.yml new file mode 100644 index 000000000..4b46a87bb --- /dev/null +++ b/changelogs/unreleased/fix-commit-size-nil-panic.yml @@ -0,0 +1,5 @@ +--- +title: Remove unnecessary commit size calculations +merge_request: 791 +author: +type: fixed diff --git a/internal/service/commit/commits_helper.go b/internal/service/commit/commits_helper.go index e6771a9d8..ae1f0071f 100644 --- a/internal/service/commit/commits_helper.go +++ b/internal/service/commit/commits_helper.go @@ -14,6 +14,8 @@ type commitsSender interface { Send([]*pb.GitCommit) error } +const commitsPerChunk = 20 + func sendCommits(ctx context.Context, sender commitsSender, repo *pb.Repository, revisionRange []string, paths []string, extraArgs ...string) error { cmd, err := log.GitLogCommand(ctx, repo, revisionRange, paths, extraArgs...) if err != nil { @@ -26,18 +28,15 @@ func sendCommits(ctx context.Context, sender commitsSender, repo *pb.Repository, } var commits []*pb.GitCommit - commitsSize := 0 for logParser.Parse() { commit := logParser.Commit() - commitsSize += commitSize(commit) - if commitsSize >= maxMsgSize { + if len(commits) >= commitsPerChunk { if err := sender.Send(commits); err != nil { return err } commits = nil - commitsSize = 0 } commits = append(commits, commit) @@ -59,10 +58,3 @@ func sendCommits(ctx context.Context, sender commitsSender, repo *pb.Repository, return nil } - -func commitSize(commit *pb.GitCommit) int { - return len(commit.Id) + len(commit.Subject) + len(commit.Body) + - len(commit.Author.Name) + len(commit.Author.Email) + len(commit.Committer.Name) + len(commit.Committer.Email) + - 8 + 8 + // Author and Committer timestamps are int64 - len(commit.ParentIds)*40 -} diff --git a/internal/service/commit/server.go b/internal/service/commit/server.go index 7607d6f48..eb2f3046d 100644 --- a/internal/service/commit/server.go +++ b/internal/service/commit/server.go @@ -13,7 +13,6 @@ type server struct { var ( defaultBranchName = ref.DefaultBranchName - maxMsgSize = 1024 * 128 // 128 KiB ) // NewServer creates a new instance of a grpc CommitServiceServer |