Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit ffbbcca

Browse files
authored
search: simplify Deduper (#61139)
Apart from the expected deduping based on `Match.Key()`, `Deduper` kept track of the deduped results but none of the call sites ever read the results. On top of that, `Deduper` modified the matches passed to it via `Deduper.Add` which, looking at the call sites, I don't think was intentional, because all call sites keep track of results themselves. The test I fix in the second commit documents that behavior. Notes: - I also removed NewDedupingStream which was unused. Test plan: - updated unit test - CI
1 parent abf9ce3 commit ffbbcca

File tree

8 files changed

+140
-276
lines changed

8 files changed

+140
-276
lines changed

internal/search/job/jobutil/select_test.go

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -45,73 +45,51 @@ func TestWithSelect(t *testing.T) {
4545
}
4646

4747
autogold.Expect(`[
48-
{
49-
"Path": "pokeman/",
50-
"PreciseLanguage": "",
51-
"ChunkMatches": null,
52-
"PathMatches": null,
53-
"LimitHit": false
54-
},
55-
{
56-
"Path": "digiman/",
57-
"PreciseLanguage": "",
58-
"ChunkMatches": null,
59-
"PathMatches": null,
60-
"LimitHit": false
61-
}
62-
]`).Equal(t, test("file.directory"))
48+
{
49+
"Path": "pokeman/",
50+
"PreciseLanguage": "",
51+
"ChunkMatches": null,
52+
"PathMatches": null,
53+
"LimitHit": false
54+
},
55+
{
56+
"Path": "digiman/",
57+
"PreciseLanguage": "",
58+
"ChunkMatches": null,
59+
"PathMatches": null,
60+
"LimitHit": false
61+
}
62+
]`).Equal(t, test("file.directory"))
6363

6464
autogold.Expect(`[
65-
{
66-
"Path": "pokeman/charmandar",
67-
"PreciseLanguage": "",
68-
"ChunkMatches": null,
69-
"PathMatches": null,
70-
"LimitHit": false
71-
},
72-
{
73-
"Path": "pokeman/bulbosaur",
74-
"PreciseLanguage": "",
75-
"ChunkMatches": null,
76-
"PathMatches": null,
77-
"LimitHit": false
78-
},
79-
{
80-
"Path": "digiman/ummm",
81-
"PreciseLanguage": "",
82-
"ChunkMatches": null,
83-
"PathMatches": null,
84-
"LimitHit": false
85-
}
86-
]`).Equal(t, test("file"))
65+
{
66+
"Path": "pokeman/charmandar",
67+
"PreciseLanguage": "",
68+
"ChunkMatches": null,
69+
"PathMatches": null,
70+
"LimitHit": false
71+
},
72+
{
73+
"Path": "pokeman/bulbosaur",
74+
"PreciseLanguage": "",
75+
"ChunkMatches": null,
76+
"PathMatches": null,
77+
"LimitHit": false
78+
},
79+
{
80+
"Path": "digiman/ummm",
81+
"PreciseLanguage": "",
82+
"ChunkMatches": null,
83+
"PathMatches": null,
84+
"LimitHit": false
85+
}
86+
]`).Equal(t, test("file"))
8787

8888
autogold.Expect(`[
8989
{
9090
"Path": "pokeman/charmandar",
9191
"PreciseLanguage": "",
9292
"ChunkMatches": [
93-
{
94-
"Content": "",
95-
"ContentStart": [
96-
0,
97-
0,
98-
0
99-
],
100-
"Ranges": [
101-
{
102-
"start": [
103-
0,
104-
0,
105-
0
106-
],
107-
"end": [
108-
0,
109-
0,
110-
0
111-
]
112-
}
113-
]
114-
},
11593
{
11694
"Content": "",
11795
"ContentStart": [

internal/search/result/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ go_library(
77
"commit.go",
88
"commit_diff.go",
99
"commit_json.go",
10-
"deduper.go",
1110
"file.go",
1211
"highlight.go",
1312
"match.go",
@@ -43,7 +42,6 @@ go_test(
4342
"commit_diff_test.go",
4443
"commit_json_test.go",
4544
"commit_test.go",
46-
"deduper_test.go",
4745
"file_test.go",
4846
"match_test.go",
4947
"merger_test.go",

internal/search/result/deduper.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

internal/search/result/deduper_test.go

Lines changed: 0 additions & 125 deletions
This file was deleted.

internal/search/result/match.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,19 @@ func (m Matches) ResultCount() int {
146146
}
147147
return count
148148
}
149+
150+
// Deduper is a convenience type to deduplicate matches
151+
type Deduper map[Key]struct{}
152+
153+
func NewDeduper() Deduper {
154+
return make(map[Key]struct{})
155+
}
156+
157+
func (d Deduper) Add(m Match) {
158+
d[m.Key()] = struct{}{}
159+
}
160+
161+
func (d Deduper) Seen(m Match) bool {
162+
_, ok := d[m.Key()]
163+
return ok
164+
}

0 commit comments

Comments
 (0)