Closed Bug 1591327 Opened 5 years ago Closed 5 years ago

Properly limit results to maxResults while taking result spans into account.

Categories

(Firefox :: Address Bar, defect, P1)

defect
Points:
3

Tracking

()

RESOLVED FIXED
Firefox 72
Iteration:
72.1 - Oct 21 - Nov 3
Tracking Status
firefox70 --- unaffected
firefox71 --- fixed
firefox72 --- fixed

People

(Reporter: adw, Assigned: adw)

References

Details

Attachments

(2 files)

This is a vague bug report, but I'm not sure what's going on yet. I'll clarify it and file other bugs as necessary as I investigate it.

I have a stub interventions extension to test the query categorization module I'm writing. All it does is register a provider that creates a tip result whose text depends on the matched category. In debugging this, I also tested with a bare-bones provider that creates a static tip, and the problems still happen.

When my provider returns the "active" behavior (so that the tip is interleaved in the normal results), the view flickers and doesn't display any results as I type. If the provider's behavior is "restricting", the tip appears by itself as expected, but when the provider later returns "inactive" (because the search string doesn't match a category), the normal heuristic result has the tip's button in it. And then when the tip is shown later, it sometimes has the "-- Search with ..." text in it.

There are a bunch of errors in the console as this is all happening.

Returning interleaved results with types URL and SEARCH works correctly, so this does seem to be related to tips in particular.

There's something wrong with the handled logic in the muxer. The muxer's sort is called many times for the same context as results are added. The handled set is recreated each time. So we end up "handling" some of the same results several times per context.

For normal results, that doesn't seem to be a problem. For tip results, their span is 3, so when sort does context.maxResults -= UrlbarUtils.getSpanForResult(result) - 1, it decreases the maxResults by 2, and since the tip result is handled more than once, maxResults ends up getting decreased too much, eventually to zero, which is why the view ends up empty. For normal results, UrlbarUtils.getSpanForResult(result) - 1 is just zero, so there's no problem there.

Not sure yet what exactly we should be doing here, whether the handled logic needs to be fixed, or maybe we shouldn't be decreasing maxResults at all. I thought that saving the handled set per context would fix it, but it doesn't.

why are we changing context.maxResults in the muxer? that looks wrong, it's just an information that the context is providing, modifying it doesn't seem to make any sense.

If the scope is so we won't fetch more results than expected, that was not intended to work like that, the muxer will just cut an adequate number of results, returning more results from providers is absolutely fine, up to maxResults. Indeed I'd consider it a bug, if the muxer decides to throw away one of these large resultSpan results, it would not have other results to pick from.

Yes, decreasing context.maxResults definitely is wrong, but what I was less clear on is whether the handled logic is working incorrectly, too. On closer look, I think it's working fine. Note also that UrlbarProvidersManager is the piece that crops the results to maxResults. So the right fix is to move the result-span checking into UrlbarProvidersManager's cropping afaict.

(In reply to Drew Willcoxon :adw from comment #5)

Yes, decreasing context.maxResults definitely is wrong, but what I was less clear on is whether the handled logic is working incorrectly, too. On closer look, I think it's working fine. Note also that UrlbarProvidersManager is the piece that crops the results to maxResults.

ah right, the muxer sorts and then the PM crops. There's no strict reason about that split, both solutions would be fine. I suspect I put the cropping in the pm so that the muxer had less responsibilities :shrug:.

The reason I'm hitting the maxResults problem but browser_urlbar_resultSpan.js doesn't is related to how many times the muxer's sort method is called. browser_urlbar_resultSpan.js adds one restricting provider, so it effectively disables UnifiedComplete, and it adds all its results synchronously. The provider's type is not immediate. Therefore, sort is called only once per search, when the _chunkTimer in the providers manager fires. Because sort is called only once, subtracting the tip's result span in the muxer is harmless.

The UnifiedComplete provider alone also doesn't have this problem, but for a different reason. The UnifiedComplete provider is immediate, so sort is called for each result in the search. But of course UnifiedComplete doesn't have tip results, so it's not affected.

But when you have a non-restricting extension provider, you have async results from the extension plus UnifiedComplete, so sort gets called multiple times per search.

The muxer shouldn't decrease maxResults. The cropping in the providers manager should take result spans into account.

I updated the result-span test to also check a non-restricting provider, which triggers this bug.

(In reply to Drew Willcoxon :adw from comment #0)

When my provider returns the "active" behavior (so that the tip is interleaved in the normal results), the view flickers and doesn't display any results as I type.

This patch kind of fixes this problem. Now the tip is shown, but it doesn't look right at first, and other results from UnifiedComplete that should be shown aren't. And there are still the JS errors in the view. I'll morph this bug to be about the maxResults problem and file a new one for investigating the remaining problems.

Summary: Tips don't work properly when created by an extension → Properly limit results to maxResults while taking result spans into account.
See Also: → 1592172
Pushed by dwillcoxon@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/cf21b0dd7d7a Quantumbar: Properly limit results to maxResults while taking result spans into account. r=mak
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 72
Attached patch Beta 71 patchSplinter Review

Beta/Release Uplift Approval Request

  • User impact if declined: We'd like the option of running quantumbar experiments on 71 that require this patch (bug 1564506, bug 1568594). Otherwise we'd need to wait until 72.
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: No
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): This is a bug fix that properly limits the number of results shown in the quantumbar when special "tip" results are present. Tip results would only be shown by experiment extensions and are not shown in normal Firefox.
  • String changes made/needed:
Attachment #9105073 - Flags: approval-mozilla-beta?
Flags: qe-verify-
Flags: in-testsuite+
Comment on attachment 9105073 [details] [diff] [review] Beta 71 patch Covered by tests, needed for 71 experiments and evaluated as low risk by the developer, uplift approved for 71 beta 6, thanks.
Attachment #9105073 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: