Skip to content

fix: remove broken stale request check and handle network errors in autocomplete#7441

Open
Sherley-Sonali wants to merge 3 commits intoopenfoodfacts:developfrom
Sherley-Sonali:fix/autocomplete-stale-requests
Open

fix: remove broken stale request check and handle network errors in autocomplete#7441
Sherley-Sonali wants to merge 3 commits intoopenfoodfacts:developfrom
Sherley-Sonali:fix/autocomplete-stale-requests

Conversation

@Sherley-Sonali
Copy link

@Sherley-Sonali Sherley-Sonali commented Mar 7, 2026

⚠️ Acceptance Requirements

What

  • Removed the broken time-based stale request check in _getSuggestions.
    start.difference(DateTime.now()).inSeconds always returns a negative value,
    so the condition > 5 never triggered. This was dead code.
  • Stale request ordering is already handled correctly by AutocompleteManager
    in openfoodfacts-dart, this confirms the "to be confirmed" from the issue discussion.
  • Fixed silent catch block: on network failure, the loading spinner now always
    hides and empty results are returned cleanly instead of leaving the user
    with a stuck spinner.

Screenshot or video

No visual change — this is a logic fix. Spinner now correctly disappears
on network failure instead of staying indefinitely.

Fixes bug(s)

Part of

@github-actions github-actions bot added ✏️ Editing Many products are incomplete and don't have Nutri-Score, Eco-Score…so editing is important for users autocomplete labels Mar 7, 2026
@teolemon teolemon requested a review from a team March 7, 2026 09:27
Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Sherley-Sonali!
The first step would be to format your code, cf. dart format .

Copy link
Contributor

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Sherley-Sonali!

Please have a look at my comments.

I guess the code would indeed need some refactoring. But I'm not sure you're actually fixing the initial issue.

The assumption that caching the lists in static variables isn't good enough, offline (or worse: with low connectivity), and with recurring queries.
I cannot even find that caching in the code, beyond mere local variables - would you help me?

A solution would be to store (and reuse) the lists locally, e.g. in SQFlite in a new table.

Then, when the user types in something:

  • let's have a look in the local database
  • if we find something in the database, we return it, while refreshing the database with the values returned by the call to the server - will be reused for the next time
  • if there's nothing in the database, we also call the server, store the list and return it

What do you think of that?

Comment on lines +223 to +226
} catch (_) {
_setLoading(false);
return _SearchResults.empty();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (_) {
_setLoading(false);
return _SearchResults.empty();
}
} catch (_) {
return _SearchResults.empty();
} finally {
_setLoading(false);
}

We're through with the loading process by now, aren't we?

} else {
return _suggestions[search] ?? _SearchResults.empty();
}
return _suggestions[search] ?? _SearchResults.empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return _suggestions[search] ?? _SearchResults.empty();
return _suggestions[search]!;

At this point _suggestions[search] is always populated, isn't it?

@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 9.10%. Comparing base (4d9c7fc) to head (2cc94a8).
⚠️ Report is 1354 commits behind head on develop.

Files with missing lines Patch % Lines
...ib/pages/input/smooth_autocomplete_text_field.dart 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           develop   #7441      +/-   ##
==========================================
- Coverage     9.54%   9.10%   -0.44%     
==========================================
  Files          325     625     +300     
  Lines        16411   36636   +20225     
==========================================
+ Hits          1567    3337    +1770     
- Misses       14844   33299   +18455     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autocomplete ✏️ Editing Many products are incomplete and don't have Nutri-Score, Eco-Score…so editing is important for users

Projects

Status: 💬 To discuss and validate

Development

Successfully merging this pull request may close these issues.

Auto-completion is often very slow

3 participants