Skip to content

Commit

Permalink
eval: simplify query.RawConfig (#833)
Browse files Browse the repository at this point in the history
While working on scoring I noticed that public repos always have an
advantage compared to private repos, because we have
`doc(rawConfig:RcOnlyPublic|...)` as part of the matchtree, which
contributues +1 to the atom count.

Test plan:
New unit test
  • Loading branch information
stefanhengl authored Sep 24, 2024
1 parent 5379bc9 commit a6e3dc2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func (d *indexData) simplify(in query.Q) query.Q {
return d.simplifyMultiRepo(q, func(repo *Repository) bool {
return r.Set[repo.Name]
})
case query.RawConfig:
return d.simplifyMultiRepo(q, func(repo *Repository) bool { return uint8(r)&encodeRawConfig(repo.RawConfig) == uint8(r) })
case *query.RepoIDs:
return d.simplifyMultiRepo(q, func(repo *Repository) bool {
return r.Repos.Contains(repo.ID)
Expand Down
16 changes: 16 additions & 0 deletions eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,22 @@ func TestSimplifyRepoRegexp(t *testing.T) {
}
}

func TestSimplifyRcRawConfig(t *testing.T) {
d := compoundReposShard(t, "foo", "bar")
var all = query.RcOnlyPrivate | query.RcNoForks | query.RcNoArchived

got := d.simplify(all)
if d := cmp.Diff(&query.Const{Value: true}, got); d != "" {
t.Fatalf("-want, +got:\n%s", d)
}

var none = query.RcOnlyPublic | query.RcNoForks | query.RcNoArchived
got = d.simplify(none)
if d := cmp.Diff(&query.Const{Value: false}, got); d != "" {
t.Fatalf("-want, +got:\n%s", d)
}
}

func TestSimplifyBranchesRepos(t *testing.T) {
d := compoundReposShard(t, "foo", "bar")

Expand Down

0 comments on commit a6e3dc2

Please sign in to comment.