From 72c030e1a470ad0004cc972288c4c5b06e2171d0 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Thu, 18 Nov 2021 22:07:51 +0100
Subject: [PATCH] [WIP] REPO: Select the update function version

The version of the update function is chosen depending on the URI that
is passed to the update method of the repo module:
- An ID URI: the ___worker_update_from_ids is selected, the user will be
  able to queue the different kara to download by calling again the
  update method with others ID URI
- Anything else: the ___worker_update is selected. It will download all
  the database from Kurisu, filtering if the passed URI is not URI_NULL.

The aim here is to offer a download process option which permit the user
of doing a simple dry-update and then selecting the different karas he
wants to download id per id.
---
 src/module/module_repo.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/module/module_repo.c b/src/module/module_repo.c
index 1235aaa4..0fe6f19d 100644
--- a/src/module/module_repo.c
+++ b/src/module/module_repo.c
@@ -1076,8 +1076,16 @@ mod_update(va_list *va)
             args->filter_uri                    = lkt_uri_copy(uri_ptr);
 
             /* `args` and `args->filter_uri` are moved, is owner is now
-             * `___worker_update`. That function will free those pointers. */
-            if (worker_pool_push(&(*repo)->workers, ___worker_update, (void *)args)) {
+             * `___worker_update`. That function will free those pointers. We
+             * also select the update fonction version depending on the query,
+             * if the query is an id, we will use the *from_ids* version,
+             * enabling the user to queue the different kara to dl by their ID */
+
+            const worker_function update_version = (lkt_uri_get_type(args->filter_uri) == URI_ID)
+                                                       ? ___worker_update_from_ids
+                                                       : ___worker_update;
+
+            if (worker_pool_push(&(*repo)->workers, update_version, (void *)args)) {
                 LOG_ERROR("REPO", "Out of memory");
                 ret = 1;
             } else
-- 
GitLab