Merge lp:~ruben-reina-dev/appcenter/fix_search_freezes into lp:~elementary-apps/appcenter/appcenter

Proposed by Rubén Reina
Status: Merged
Approved by: Danielle Foré
Approved revision: 278
Merged at revision: 278
Proposed branch: lp:~ruben-reina-dev/appcenter/fix_search_freezes
Merge into: lp:~elementary-apps/appcenter/appcenter
Diff against target: 50 lines (+14/-6)
2 files modified
src/MainWindow.vala (+1/-1)
src/Views/SearchView.vala (+13/-5)
To merge this branch: bzr merge lp:~ruben-reina-dev/appcenter/fix_search_freezes
Reviewer Review Type Date Requested Status
Danielle Foré Approve
Review via email: mp+303484@code.launchpad.net

Commit message

* Search asynchronously
* Limit search results to 100 (for responsiveness)

Description of the change

After examining this bug, the changes I have applied are:
 - Ask the core (Client) for apps and add the apps to the UI in an asynchronous method.
 - Limit the number of displayed apps in a search result to 100. I have done this to improve the search responsiveness not overloading the UI too much.

To post a comment you must log in.
Revision history for this message
Danielle Foré (danrabbit) wrote :

Does what it says on the tin :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/MainWindow.vala'
2--- src/MainWindow.vala 2016-06-29 01:20:31 +0000
3+++ src/MainWindow.vala 2016-08-20 17:03:54 +0000
4@@ -177,7 +177,7 @@
5 break;
6 }
7 } else {
8- search_view.search (research);
9+ search_view.search.begin (research);
10 if (!return_button.visible) {
11 view_mode_revealer.reveal_child = false;
12 stack.visible_child = search_view;
13
14=== modified file 'src/Views/SearchView.vala'
15--- src/Views/SearchView.vala 2015-12-10 19:53:13 +0000
16+++ src/Views/SearchView.vala 2016-08-20 17:03:54 +0000
17@@ -21,6 +21,7 @@
18 using AppCenterCore;
19
20 public class AppCenter.Views.SearchView : View {
21+ const int MAX_NUMBER_OF_SEARCH_RESULTS = 100;
22 AppListView app_list_view;
23
24 public SearchView () {
25@@ -40,13 +41,20 @@
26 public override void return_clicked () {
27 set_visible_child (app_list_view);
28 }
29-
30- public void search (string search_term) {
31+
32+ public async void search (string search_term) {
33+ app_list_view.clear ();
34 unowned Client client = Client.get_default ();
35 var found_apps = client.search_applications (search_term);
36- app_list_view.clear ();
37- foreach (var app in found_apps) {
38- app_list_view.add_package (app);
39+
40+ if (found_apps.size > 0) {
41+ var apps_array = found_apps.to_array ();
42+ int i = 0;
43+ while (i < apps_array.length && i < MAX_NUMBER_OF_SEARCH_RESULTS) {
44+ var app = apps_array[i];
45+ app_list_view.add_package (app);
46+ i++;
47+ }
48 }
49 }
50 }

Subscribers

People subscribed via source and target branches