Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/code: Rediscover only within the affected repository.
This change is an optimization for code.Service.Rediscover method. Instead of always rediscovering the entire store, limit scope to just the affected repository. Time to Rediscover with sample test data went from 13 ms to 6 ms. This optimization will have a significant impact when the entire repository store is very large compared to the single repository being updated.
- Loading branch information
Showing
4 changed files
with
205 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package code | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestReplaceDirs(t *testing.T) { | ||
tests := []struct { | ||
s []*Directory | ||
repoRoot string | ||
dirs []*Directory | ||
want []*Directory | ||
}{ | ||
// 2 -> 1 (shrink by 1). | ||
{ | ||
s: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "b", ImportPath: "b/1"}, | ||
{RepoRoot: "b", ImportPath: "b/2"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
repoRoot: "b", | ||
dirs: []*Directory{ | ||
{RepoRoot: "b", ImportPath: "b/3"}, | ||
}, | ||
want: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "b", ImportPath: "b/3"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
}, | ||
// 2 -> 2 (stay same size). | ||
{ | ||
s: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "b", ImportPath: "b/1"}, | ||
{RepoRoot: "b", ImportPath: "b/2"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
repoRoot: "b", | ||
dirs: []*Directory{ | ||
{RepoRoot: "b", ImportPath: "b/3"}, | ||
{RepoRoot: "b", ImportPath: "b/4"}, | ||
}, | ||
want: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "b", ImportPath: "b/3"}, | ||
{RepoRoot: "b", ImportPath: "b/4"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
}, | ||
// 2 -> 3 (grow by 1). | ||
{ | ||
s: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "b", ImportPath: "b/1"}, | ||
{RepoRoot: "b", ImportPath: "b/2"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
repoRoot: "b", | ||
dirs: []*Directory{ | ||
{RepoRoot: "b", ImportPath: "b/3"}, | ||
{RepoRoot: "b", ImportPath: "b/4"}, | ||
{RepoRoot: "b", ImportPath: "b/5"}, | ||
}, | ||
want: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "b", ImportPath: "b/3"}, | ||
{RepoRoot: "b", ImportPath: "b/4"}, | ||
{RepoRoot: "b", ImportPath: "b/5"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
}, | ||
|
||
// 2 -> 0. | ||
{ | ||
s: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "b", ImportPath: "b/1"}, | ||
{RepoRoot: "b", ImportPath: "b/2"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
repoRoot: "b", | ||
dirs: nil, | ||
want: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
}, | ||
// 0 -> 2. | ||
{ | ||
s: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
repoRoot: "b", | ||
dirs: []*Directory{ | ||
{RepoRoot: "b", ImportPath: "b/1"}, | ||
{RepoRoot: "b", ImportPath: "b/2"}, | ||
}, | ||
want: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "b", ImportPath: "b/1"}, | ||
{RepoRoot: "b", ImportPath: "b/2"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
}, | ||
// 0 -> 0. | ||
{ | ||
s: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
repoRoot: "b", | ||
dirs: nil, | ||
want: []*Directory{ | ||
{RepoRoot: "a", ImportPath: "a"}, | ||
{RepoRoot: "c", ImportPath: "c"}, | ||
}, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
got := tc.s | ||
replaceDirs(&got, tc.repoRoot, tc.dirs) | ||
if !reflect.DeepEqual(got, tc.want) { | ||
t.Error("not equal") | ||
} | ||
} | ||
} |