From 75c11225c6d51f1fea22933930a7b7120c2a3bbf Mon Sep 17 00:00:00 2001
From: davelopez <46503462+davelopez@users.noreply.github.com>
Date: Tue, 12 Dec 2023 17:13:03 +0100
Subject: [PATCH 1/2] Add test to check workflow index total matches

---
 lib/galaxy_test/api/test_workflows.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/lib/galaxy_test/api/test_workflows.py b/lib/galaxy_test/api/test_workflows.py
index 4483a096ef6a..0705fac183ea 100644
--- a/lib/galaxy_test/api/test_workflows.py
+++ b/lib/galaxy_test/api/test_workflows.py
@@ -727,6 +727,33 @@ def test_index_parameter_invalid_combinations(self):
         self._assert_status_code_is(response, 400)
         self._assert_error_code_is(response, error_codes.error_codes_by_name["USER_REQUEST_INVALID_PARAMETER"])
 
+    def test_index_total_matches(self):
+        with self._different_user("isolated.wf.user@test.email"):
+            my_workflow_id = self.workflow_populator.simple_workflow("mine_1")
+            self.workflow_populator.simple_workflow("mine_2")
+            my_email = self.dataset_populator.user_email()
+            with self._different_user():
+                their_shared_workflow_id = self.workflow_populator.simple_workflow("theirs_1")
+                self.workflow_populator.share_with_user(their_shared_workflow_id, my_email)
+                their_workflow_to_import_id = self.workflow_populator.simple_workflow("theirs_2", publish=True)
+                self.workflow_populator.set_tags(their_workflow_to_import_id, ["theirs_2", "test"])
+
+            import_response = self.__import_workflow(their_workflow_to_import_id)
+            self._assert_status_code_is(import_response, 200)
+            imported_wf_id = import_response.json()["id"]
+
+            # add tags to my workflows
+            self.workflow_populator.set_tags(my_workflow_id, ["mine_1", "test"])
+            self.workflow_populator.set_tags(imported_wf_id, ["imported", "test"])
+
+            # We should have 4 workflows now (2 mine, 1 shared with me, 1 imported)
+            expected_number_of_workflows = 4
+            workflows_response = self._get("workflows")
+            self._assert_status_code_is(workflows_response, 200)
+            assert workflows_response.headers["Total_matches"] == f"{expected_number_of_workflows}"
+            workflows = workflows_response.json()
+            assert len(workflows) == expected_number_of_workflows
+
     def test_upload(self):
         self.__test_upload(use_deprecated_route=False)
 

From fa585e1ac71b743780fdc0f5fd53ebcad7b60571 Mon Sep 17 00:00:00 2001
From: davelopez <46503462+davelopez@users.noreply.github.com>
Date: Tue, 12 Dec 2023 17:14:07 +0100
Subject: [PATCH 2/2] Fix workflow index total matches wrong count

---
 lib/galaxy/managers/workflows.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/galaxy/managers/workflows.py b/lib/galaxy/managers/workflows.py
index 58bc7e52a2b6..ee6fc211f6ae 100644
--- a/lib/galaxy/managers/workflows.py
+++ b/lib/galaxy/managers/workflows.py
@@ -224,7 +224,7 @@ def name_filter(term):
                             term,
                         )
                     )
-        query = query.filter(model.StoredWorkflow.table.c.deleted == (true() if show_deleted else false()))
+        query = query.filter(model.StoredWorkflow.table.c.deleted == (true() if show_deleted else false())).distinct()
         if include_total_count:
             total_matches = query.count()
         else: