Skip to content

Commit

Permalink
Merge pull request #507 from mjakeman/remove-popularity
Browse files Browse the repository at this point in the history
Fix race condition and remove broken popularity search
  • Loading branch information
oscfdezdz authored Nov 16, 2023
2 parents c41ac00 + 7bf64db commit 1f7ccd1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/exm-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ exm_application_open (GApplication *app,
}

uuid = g_uri_get_host (uri);
g_print ("Opening extension with UUID: '%s'\n", uuid);
g_info ("Opening extension with UUID: '%s'\n", uuid);
gtk_widget_activate_action (GTK_WIDGET (window), "win.show-detail", "s", uuid);
}

Expand Down
2 changes: 1 addition & 1 deletion src/exm-backtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exm_backtrace_error_cb (void *data,
const char *msg,
int errnum)
{
g_print ("Error (%d): %s\n", errnum, msg);
g_warning ("Error (%d): %s\n", errnum, msg);
}

static int
Expand Down
2 changes: 1 addition & 1 deletion src/exm-browse-page.blp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ template $ExmBrowsePage : Gtk.Widget {
Gtk.DropDown search_dropdown {
model: StringList {
// Translators: dropdown items for sorting search results
strings [_("Relevance"), _("Popularity"), _("Downloads"), _("Recent"), _("Name")]
strings [_("Relevance"), _("Downloads"), _("Recent"), _("Name")]
};
}
}
Expand Down
15 changes: 13 additions & 2 deletions src/exm-browse-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ struct _ExmBrowsePage
int current_page;
int max_pages;

GCancellable *cancellable;

// Template Widgets
GtkSearchEntry *search_entry;
GtkListBox *search_results;
Expand Down Expand Up @@ -237,9 +239,13 @@ on_load_more_results (GtkButton *btn,
ExmSearchSort sort;
gtk_widget_set_sensitive (GTK_WIDGET (self->more_results_btn), FALSE);

// If we have a current operation, cancel it
g_cancellable_cancel (self->cancellable);
self->cancellable = g_cancellable_new ();

query = gtk_editable_get_text (GTK_EDITABLE (self->search_entry));
sort = (ExmSearchSort) gtk_drop_down_get_selected (self->search_dropdown);
exm_search_provider_query_async (self->search, query, ++self->current_page, sort, NULL,
exm_search_provider_query_async (self->search, query, ++self->current_page, sort, self->cancellable,
(GAsyncReadyCallback) on_next_page_result,
self);
}
Expand All @@ -256,7 +262,11 @@ search (ExmBrowsePage *self,
if (self->search_results_model)
g_clear_object (&self->search_results_model);

exm_search_provider_query_async (self->search, query, 1, sort, NULL,
// If we have a current operation, cancel it
g_cancellable_cancel (self->cancellable);
self->cancellable = g_cancellable_new ();

exm_search_provider_query_async (self->search, query, 1, sort, self->cancellable,
(GAsyncReadyCallback) on_first_page_result,
self);
}
Expand Down Expand Up @@ -444,3 +454,4 @@ exm_browse_page_init (ExmBrowsePage *self)

load_suggestions (self);
}

2 changes: 0 additions & 2 deletions src/web/exm-comment-provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ parse_comments (GBytes *bytes,

data = g_bytes_get_data (bytes, &length);

// g_print ("%s\n", (gchar *)data);

parser = json_parser_new ();
if (json_parser_load_from_data (parser, data, length, &error))
{
Expand Down
12 changes: 9 additions & 3 deletions src/web/exm-search-provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ parse_search_results (GBytes *bytes,
g_assert (json_object_has_member (root_object, "numpages"));

num_pages = json_object_get_int_member (root_object, "numpages");
g_print ("Num Pages: %d\n", num_pages);
g_info ("Num Pages: %d\n", num_pages);

JsonArray *array = json_object_get_array_member (root_object, "extensions");
GList *search_results = json_array_get_elements (array);
Expand Down Expand Up @@ -159,8 +159,6 @@ get_sort_string (ExmSearchSort sort_type)
return "created";
case EXM_SEARCH_SORT_NAME:
return "name";
case EXM_SEARCH_SORT_POPULARITY:
return "popularity";
case EXM_SEARCH_SORT_RELEVANCE:
default:
return "relevance";
Expand Down Expand Up @@ -205,6 +203,14 @@ exm_search_provider_query_finish (ExmSearchProvider *self,
SearchRequestData *data;
GListModel *list_model;

// Check whether the task has been cancelled and if so, return null
// This prevents a race condition in the search logic
GCancellable *cancellable = g_task_get_cancellable (G_TASK (result));
if (g_cancellable_is_cancelled (cancellable)) {
return NULL;
}


ret = exm_request_handler_request_finish (EXM_REQUEST_HANDLER (self),
result,
error);
Expand Down
7 changes: 3 additions & 4 deletions src/web/exm-search-provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ G_DECLARE_FINAL_TYPE (ExmSearchProvider, exm_search_provider, EXM, SEARCH_PROVID
typedef enum
{
EXM_SEARCH_SORT_RELEVANCE = 0,
EXM_SEARCH_SORT_POPULARITY = 1,
EXM_SEARCH_SORT_DOWNLOADS = 2,
EXM_SEARCH_SORT_RECENT = 3,
EXM_SEARCH_SORT_NAME = 4
EXM_SEARCH_SORT_DOWNLOADS = 1,
EXM_SEARCH_SORT_RECENT = 2,
EXM_SEARCH_SORT_NAME = 3
} ExmSearchSort;

ExmSearchProvider *exm_search_provider_new (void);
Expand Down

0 comments on commit 1f7ccd1

Please sign in to comment.