[grilo-plugins] tmdb: without config, run a single request



commit 9ba39b357b454912b7f7502c64dd76af4978c5ac
Author: Victor Toso <victortoso gnome org>
Date:   Sun Aug 21 11:43:03 2022 +0200

    tmdb: without config, run a single request
    
    When we need to request the config, the request's callback will flush
    out the queue of requests. So, when we need the config, be sure to
    only run_pending_requests with max_num_request set to 1.
    
    Also, to avoid reuse of the same GrlTmdbRequest, I've added a warning
    to its grl_tmdb_request_run_async().
    
    Found this after switching internals of GrlNetWc to use GTask instead
    of GSimpleAsyncResult.

 src/tmdb/grl-tmdb-request.c | 6 ++++++
 src/tmdb/grl-tmdb.c         | 5 ++++-
 2 files changed, 10 insertions(+), 1 deletion(-)
---
diff --git a/src/tmdb/grl-tmdb-request.c b/src/tmdb/grl-tmdb-request.c
index c17ba8bb..2c6a18e4 100644
--- a/src/tmdb/grl-tmdb-request.c
+++ b/src/tmdb/grl-tmdb-request.c
@@ -575,6 +575,12 @@ grl_tmdb_request_run_async (GrlTmdbRequest *self,
     call = new_call;
   }
 
+  if (self->priv->task != NULL) {
+      GRL_WARNING("Request %p to %s is already in progress", self, call);
+      g_free (call);
+      return;
+  }
+
   self->priv->task = g_task_new (G_OBJECT (self),
                                  cancellable,
                                  callback,
diff --git a/src/tmdb/grl-tmdb.c b/src/tmdb/grl-tmdb.c
index 99f3391e..727d253e 100644
--- a/src/tmdb/grl-tmdb.c
+++ b/src/tmdb/grl-tmdb.c
@@ -1377,7 +1377,6 @@ grl_tmdb_source_resolve (GrlSource *source,
     GRL_DEBUG ("Running initial search for title \"%s\"...", title);
     request = grl_tmdb_request_new_search (closure->self->priv->api_key, title);
     queue_request (closure, request, on_search_ready);
-    run_pending_requests (closure, 1);
   } else {
     GRL_DEBUG ("Running %s lookup for movie #%" G_GUINT64_FORMAT "...",
                closure->slow ? "slow" : "fast", movie_id);
@@ -1387,7 +1386,11 @@ grl_tmdb_source_resolve (GrlSource *source,
     } else {
       queue_detail_request (closure, GRL_TMDB_REQUEST_DETAIL_MOVIE);
     }
+  }
 
+  if (self->priv->config_pending || title == NULL) {
+    run_pending_requests (closure, 1);
+  } else {
     run_pending_requests (closure, G_MAXINT);
   }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]