Skip to content

search: limit lucky search activity after enough results

Administrator requested to merge rvt/lucky-bookkeeping-2 into main

Created by: rvantonder

Stacked on https://github.com/sourcegraph/sourcegraph/pull/38448

This fixes one of the major issues I had before I want to share lucky search more broadly.

  • Problem: we would continue running generated queries indefinitely, there wasn't an upper bound

  • Follow on problem: I tried earlier to bound this by using LimitJob and cancelling on context. This turned out not to play well with what I was doing, especially when the user enters count, and difficult applying LimitJob to any of (a) the initial query (b) generated queries. I ran into trouble because it's not possible to wrap all generated queries in a limit job because they are generated on-demand in a loop, and this would need more stuff with job machinery that I don't want to deal with.

So the solution I'm happy with right now:

  • Run initial query to completion, given any users count, as before.

  • Start running generated queries after that, and count the results. When we've reached max limit streaming in aggregate (500 currently), just stop generating and running queries. If the user does apply count, count will be honored within in each generated query, but we will still stop running after 500 total.

Test plan

Covered by existing test, manual testing, and we'll test the rest in prod.

Merge request reports

Loading