From 8060ac88c31d2df9a9699e9db8e33507aa039716 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 4 Feb 2016 07:46:14 +1100 Subject: [PATCH] Don't update search query unless it has changed meaningfully. Changing the search query is quite an expensive operation, so this does some rudimentary checking to see if the two queries are meaningfully different. At present, it trims the strings and does a case insensitive comparison. The query is eventually exploded based on whitespace, so leading and trailing white space is not important. Also, sqlite `LIKE` clauses are case insensitive, so case is unimportant. Having said that, I'm not sure how someone will be able to change the queries case without first deleting and then adding characters (thus inducing meaningfull changse). --- .../fdroid/views/AppListFragmentPagerAdapter.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/F-Droid/src/org/fdroid/fdroid/views/AppListFragmentPagerAdapter.java b/F-Droid/src/org/fdroid/fdroid/views/AppListFragmentPagerAdapter.java index 9e9e47ea3..59d1d4ec4 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/AppListFragmentPagerAdapter.java +++ b/F-Droid/src/org/fdroid/fdroid/views/AppListFragmentPagerAdapter.java @@ -58,7 +58,22 @@ public class AppListFragmentPagerAdapter extends FragmentPagerAdapter { return parent.getString(R.string.tab_updates_count, updateCount); } + /** + * Changing the search query is quite an expensive operation, so this does some rudimentary + * checking to see if the two queries are meaningfully different. At present, it trims the + * strings and does a case insensitive comparison. + */ + private boolean isSearchQuerySame(String newQuery) { + String oldValueTrimmed = searchQuery == null ? "" : searchQuery.trim(); + String newValueTrimmed = newQuery == null ? "" : newQuery.trim(); + return oldValueTrimmed.equalsIgnoreCase(newValueTrimmed); + } + public void updateSearchQuery(@Nullable String query) { + if (isSearchQuerySame(query)) { + return; + } + searchQuery = query; for (AppListFragment fragment : registeredFragments) { if (fragment != null) {